MATLAB Answers

How to use different markers for different X,Y pairs?

358 views (last 30 days)
Valeriy on 30 May 2016
Commented: Ali on 29 Oct 2017
I'd like to have separated (X,Y) points, marked by different markers and legend that describes those points. When I use plot(x1,y1,'+',x2,y2,'o') I have error message. Solution with plot()... hold on; plot()... is not convenient because in such a case legend not shows all pairs information. Thanks for ideas.


Show 1 older comment
Image Analyst
Image Analyst on 30 May 2016
This works just fine with no errors.
numPoints = 10;
x1 = rand(1, numPoints);
y1 = rand(1, numPoints);
x2 = rand(1, numPoints);
y2 = rand(1, numPoints);
Please read this link and then attach ALL the red error text along with the code that generated the error.
Valeriy on 30 May 2016
Thanks Josdph Cheng and Image Analyst for quick reply. Line
produced next error message:
??? Error using ==> plot
String argument is an unknown option.
Line with suppressed color options works well:
I have a lot of X,Y pairs, so using different colors will be convenient and useful.
Ali on 29 Oct 2017
if true
--------------------------------------------------- code start
This is an example for your case
Input is "Input_Data", two dimension matrix
Markers = {'+','o','*','x','v','d','^','s','>','<'};
for i=1:10:size(Input_Data,1)
hold on
plot([0.5 1],[0.5 1],'--');
legend('Minpts = 100','Minpts = 200','Minpts = 300','Minpts = 400','Minpts = 500','Minpts = 600','Minpts = 700','Minpts = 800','Minpts = 900','Minpts = 1000','','Location','SouthEast');
xlabel('FPR or (1-Specificity)','FontSize',12,'FontWeight','bold'); ylabel('TPR or Spensitivity)','FontSize',12,'FontWeight','bold');
title('ROC Space');
-------------------------------------------- code end
--------------------------------------- picture link preview

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 30 May 2016
Plot by using two separate calls to plot:
hold on
or whatever - not sure exactly what is a point and what is an array with your x,y. But anyway, this works - I've tried it.


dpb on 31 May 2016
Yeah, OP's problem is trying to used named parameters for multiple points in a single call--that syntax isn't supported by the argument input parser altho seems from the doc that it could be so; it isn't excluded (altho I can see it could become extremely convoluted to parse).
Valeriy on 12 Aug 2016
Thanks all. Both proposed methods work well, but there is question, how to provide legend to each of Xi, Yi pair?
Image Analyst
Image Analyst on 12 Aug 2016
Did you try the legend() function?
legend('This is (X1, Y1)', 'This is (X2, Y2)');

Sign in to comment.

More Answers (2)

dpb on 30 May 2016
Edited: dpb on 1 Jun 2016
Can't use the named names multiple times in the same call, per the documentation: "Property name-value pairs apply to all the lines plotted. You cannot specify name-value pairs for each set of data."
You'll have to use
set(hL,{'markerfacecolor'},{cell array of colors}, ...
{'markeredgecolor'},{cell array of colors})
to do this it appears. NB: that to set multiple handles to different values you have to use cell arrays on both. This is documented at set with examples; it can get pretty complex, but is doable.
Just came to me that you can simplify just a tad by using the color in the linestyle string...
xlim([1 2]), ylim([1 3])
works and illustrates the cell array usage w/ set mentioned earlier.
is a variation when is single value with multiple handles.


Sign in to comment.

Walter Roberson
Walter Roberson on 31 May 2016
Property / Value pairs must be grouped together at the end. You cannot mix them with data. As soon as the first one is detected, it is assumed that everything after is a property / value pair.

  1 Comment

dpb on 1 Jun 2016
I see even I quit reading too soon, is documented near the very end of Description section: "Property name-value pairs apply to all the lines plotted. You cannot specify name-value pairs for each set of data."
So, my comment earlier of it being undocumented was in error...I'll amend that for the record.

Sign in to comment.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by