필터 지우기
필터 지우기

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

조회 수: 17 (최근 30일)
Valeriy
Valeriy 2016년 5월 30일
댓글: Ali 2017년 10월 29일
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.
  댓글 수: 4
Valeriy
Valeriy 2016년 5월 30일
편집: dpb 2016년 5월 30일
Thanks Josdph Cheng and Image Analyst for quick reply. Line
plot(RzACF.ACL(1),RzACF.Rz(1),'>','MarkerEdgeColor','y','MarkerFaceColor','m',...
RzACF.ACL(2),RzACF.Rz(2),'<','MarkerEdgeColor','m','MarkerFaceColor','c');
produced next error message:
??? Error using ==> plot
String argument is an unknown option.
Line with suppressed color options works well:
plot(RzACF.ACL(1),RzACF.Rz(1),'>',RzACF.ACL(2),RzACF.Rz(2),'<');
I have a lot of X,Y pairs, so using different colors will be convenient and useful.
Ali
Ali 2017년 10월 29일
if true
--------------------------------------------------- code start
This is an example for your case
Input is "Input_Data", two dimension matrix
Marker_Counter=1;
figure6=figure;
Markers = {'+','o','*','x','v','d','^','s','>','<'};
for i=1:10:size(Input_Data,1)
TPR=Input_Data(i:i+9,7);
FPR=Input_Data(i:i+9,8);
plot(FPR,TPR,strcat('-',Markers{Marker_Counter}));
Marker_Counter=Marker_Counter+1;
hold on
end
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');
close(gcf);
-------------------------------------------- code end
end
--------------------------------------- picture link preview

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2016년 5월 30일
Plot by using two separate calls to plot:
plot(x1(1),y1(1),'>','MarkerEdgeColor','y','MarkerFaceColor','m');
hold on
plot(x2(2),y2(2),'<','MarkerEdgeColor','m','MarkerFaceColor','c');
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.
  댓글 수: 3
Valeriy
Valeriy 2016년 8월 12일
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 2016년 8월 12일
Did you try the legend() function?
legend('This is (X1, Y1)', 'This is (X2, Y2)');

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

dpb
dpb 2016년 5월 30일
편집: dpb 2016년 6월 1일
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
hL=plot(x1,y1,lspec1,x2,y2,lspec2,...);
then
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.
ADDENDUM
Just came to me that you can simplify just a tad by using the color in the linestyle string...
hL=plot(1.1,2.3,'>r',1.8,1.8,'<g');
xlim([1 2]), ylim([1 3])
set(hL,{'markerfacecolor'},{'r';'g'})
works and illustrates the cell array usage w/ set mentioned earlier.
set(hL,{'markerfacecolor'},{'r';'g'},'markeredgecolor','k')
is a variation when is single value with multiple handles.

Walter Roberson
Walter Roberson 2016년 5월 31일
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
dpb
dpb 2016년 6월 1일
I see even I quit reading too soon, Walter...it 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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by