Conditional Marker Type in 2D Plot

조회 수: 14 (최근 30일)
PABLO GARCIA
PABLO GARCIA 2015년 9월 29일
댓글: PABLO GARCIA 2015년 9월 29일
Hi!
I need to make a 2-D plot where the data is colored according to a 2nd vector and the marker type is selected acording to a 3rd vector. So far I just managed to sort my data according to the 2nd vector, and then make 3 different plots.
x1=lambda_cng(1:9);
y1=s_hc(1:9);
x2=lambda_cng(10:18);
y2=s_hc(10:18);
x3=lambda_cng(19:27);
y3=s_hc(19:27);
h1=figure();
plot(x1,y1,'ok','MarkerSize',10,'MarkerFaceColor','k');
hold on
plot(x2,y2,'sr','MarkerSize',10,'MarkerFaceColor','r');
hold on
plot(x3,y3,'db','MarkerSize',10,'MarkerFaceColor','b');
However, from each of those series (9 values) I should change the marker type according to another vector. How can I do that? I have tried to figure out using scatter plots, but I did not manage to get any proper outcome.
Thanks in advance for the help!
Pablo
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 9월 29일
Is the marker the same for any one plot, or do you need different markers for each of the 9 values within one plot?
PABLO GARCIA
PABLO GARCIA 2015년 9월 29일
Thanks for your answer. There should be 3 different markers according to the values of the 3rd array. This profesional drawings shows how should look like :D

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

답변 (1개)

Walter Roberson
Walter Roberson 2015년 9월 29일
The MATLAB scatter() routine can only have one marker type per call. This is a limitation based upon how scatter() is implemented.
The MATLAB plot() routine can have one marker type per line that is drawn. If you are using the plot syntax of multiple vectors then you can specify the marker type after each item:
plot(x1(1:3), y1(1:3), 'ok', x1(4:6), y1(4:6), 'sk')
and so on. However, if you are using the matrix form of plot(), where you are giving a y with multiple columns and one line is to be generated for each column, then you cannot directly indicate the marker and will need to record the line object handles and change the markers there:
Y = reshape(y1,3,3);
h = plot1(x1(1:3), Y, 'k');
set(h(1), 'Marker', 'o'); set(h(2), 'Marker', 's'}; set(h(3), 'Marker', 'p');
I would suggest that you rethink how you draw, and use something like,
colors = 'krg';
shapes = 'osp';
for G = 1 : 9
x = lambda_cng(G:9:end);
y = s_hc(G:9:end);
coloridx = 1 + floor((G-1)/3);
shapeidx = 1 + mod(G-1, 3);
scatter(x, y, 'MarkerSize', 10, 'MarkerFaceColor', colors(coloridx), 'Marker', shapes(shapeidx));
end
  댓글 수: 1
PABLO GARCIA
PABLO GARCIA 2015년 9월 29일
Yep, I will try to arrange something using "for" loops. Thanks for your answer. I'll be back with the final solution...if I can. Thanks again

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by