How can I have automatic marker shapes for multiple curves
Show older comments
I have N curves to plot and some of the points are exacty on top of one another. Since Matlab automatically choose the default colors of the curves you plot, I can't see the points under the other. If there was a way to have automatic default marker shapes, then I would be able to see the points under. The thing is the number of curves is an input I can vary, that's why I can't simply specify the shape of the markers for each curve.
Accepted Answer
More Answers (1)
"The thing is the number of curves is an input I can vary, that's why I can't simply specify the shape of the markers for each curve."
That can be taken care of
makingPlots(16)
axis([0 11 -0.5 1.5])
%Making N plots
function makingPlots(N)
%Define markers to be used
markers = {'o','+','*','.','x','s','d','^','v','>','<','p','h'};
num = numel(markers);
%Random array with N columns
arr = rand(10,N);
figure
for k=1:N
val=rem(k,num)+num*(rem(k,num)==0);
plot(arr(:,k),'Marker',markers{val})
hold on
end
end
Also, instead of using the val I defined above, you can use
%1
num-rem(k,num)
%2
rem(k,num)+1
%3
randi(num)
And many other options. You can choose whatever order you want to use.
6 Comments
Voss
on 23 Aug 2023
Perhaps more intuitive than
val=rem(k,num)+num*(rem(k,num)==0);
is
val=rem(k-1,num)+1;
Antoine Boissinot
on 23 Aug 2023
Dyuman Joshi
on 24 Aug 2023
@Voss, you are right. Thanks, I'll use that from now on!
"I found that there is only 16 marker shapes ..."
@Antoine Boissinot - That is, unfortunately, a limitation of MATLAB and there's nothing we could do about it as of now.
Though I'd argue it would be better if MATLAB would let us use any of the alphabets as a marker, or the various symbols available on numbers on a keyboard.
"it would be better if MATLAB would let us use any of the alphabets as a marker, or the various symbols available on numbers on a keyboard"
A workaround might be to use text objects:
makingPlots(7,10)
axis([0 11 -0.5 1.5])
%Making N plots with M points each
function makingPlots(N,M)
%Define markers to be used
markers = 'a':'z';
num = numel(markers);
markers = markers(rem(0:N-1,num)+1);
%Random array with N columns and M rows
arr = rand(M,N);
figure
hold on
for k=1:N
h = plot(1:M,arr(:,k));
text(1:M,arr(:,k),markers(k),'Color',h.Color,'HorizontalAlignment','center')
end
end
Dyuman Joshi
on 1 Sep 2023
Voss
on 1 Sep 2023
@Dyuman Joshi: Thanks!
Categories
Find more on Annotations 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!
