How can I have automatic marker shapes for multiple curves

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.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Ag. de 2023
The relevant documentation is at https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html . Unfortunately what it implicitly indicates is, NO, there is no automatic marker choice.
What there is at the moment is LineStyleOrder, and the new (R2023a) LineStyleCyclingMethod, and ColorOrder, and a couple of related properties. That is, you can automatically cycle though line styles and you can cycle through colors; as of R2023a you can set it to cycle through both at the same time (each new line moves on to the next line style and next color).
When there are a number of lines close together, unfortunately line style and color are not always sufficient and you need markers too, but at present there is no facility for automatically cycling markers.

Más respuestas (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 comentarios

Perhaps more intuitive than
val=rem(k,num)+num*(rem(k,num)==0);
is
val=rem(k-1,num)+1;
Thank you! I found that there is only 16 marker shapes and like the accepted answer explained there are no automatic marker choice order. So the next best thing is something along the line as your answer, as long as I don't have more than 16 curves.
@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
That's a nice implementation, @Voss.
It's intereseting as one can also add Greek symbols via text as markers.
@Dyuman Joshi: Thanks!

Iniciar sesión para comentar.

Categorías

Preguntada:

el 23 de Ag. de 2023

Comentada:

el 1 de Sept. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by