Conditional Marker Type in 2D Plot

15 次查看(过去 30 天)
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