Plot multiple curves with filled markers

95 vues (au cours des 30 derniers jours)
Fernando Meneses
Fernando Meneses le 5 Août 2021
Commenté : Star Strider le 5 Août 2021
Hello, I would like to plot a series of curves in the same graphs using lines and markers, and I want that every marker is filled and with the same color than the line color.
The following code plots 3 curves with line and markers. Each curve uses the same color for markers and line, and each curve has a different color, but the markers are not filled.
plot (x1,y1,'-o')
hold on
plot(x2,y2,'-o')
plot(x3,y3,'-o')
hold off
I could manually enter the colors for each curve and solve the problem, like this:
plot (x1,y1,'r-o','MarkerFaceColor','r')
hold on
plot(x2,y2,'b-o','MarkerFaceColor','b')
plot(x3,y3,'k-o','MarkerFaceColor','k')
hold off
... but this will be very inefficient when I have to plot many curves.
Could you please help me with a smarter solution?
Thanks!

Réponse acceptée

Star Strider
Star Strider le 5 Août 2021
One approach —
x = linspace(0,10);
v = 1:5;
y = v(:)+sin(2*pi*v(:)*x);
cm = colormap(jet(size(y,1)));
figure
hold on
for k = 1:size(y,1)
plot(x, y(k,:), '-o', 'Color',cm(k,:), 'MarkerFaceColor',cm(k,:))
end
hold off
grid
xlabel('X')
ylabel('Y')
.
  2 commentaires
Fernando Meneses
Fernando Meneses le 5 Août 2021
Thanks a lot!!
Star Strider
Star Strider le 5 Août 2021
As always, my pleasure!
.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by