Conditional Marker Type in 2D Plot
14 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 29 Sep 2015
Is the marker the same for any one plot, or do you need different markers for each of the 9 values within one plot?
Answers (1)
Walter Roberson
on 29 Sep 2015
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
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!