Changing plot line colour with multiple data sets

5 vues (au cours des 30 derniers jours)
jrz
jrz le 12 Sep 2022
Commenté : jrz le 14 Sep 2022
I have a plot with 9 different data sets but 2 are coming out as the same color.
plot(xcUpper,Cp0U,'-o','k','linewidth', 2)
hold on
plot(xcUpper,Cp5U,'-o','linewidth', 2)
plot(xcUpper,Cp10U,'-o','linewidth', 2)
plot(xcUpper,Cp15U,'-o','linewidth', 2)
plot(xcUpper,Cp20U,'-o','linewidth', 2)
plot(xcUpper,CpM5U,'-o','linewidth', 2)
plot(xcUpper,CpM10U,'-o','linewidth', 2)
plot(xcUpper,CpM15U,'-o','linewidth', 2)
plot(xcUpper,CpM20U,'-o','linewidth',2)
title('NACA23012 Cp Distribution (Upper Surface)')
grid on
grid minor
xlabel('x/c (m)','FontSize',18)
ylabel('Pressure Coefficient','FontSize', 18)
box on
set(gca,'GridLineStyle','-')
set(gca,'MinorGridLineStyle','-')
set(gca,'GridColor','k')
set(gca,'MinorGridColor','k')
legend('\alpha = 0^\circ','\alpha = 5^\circ','\alpha = 10^\circ','\alpha = 15^\circ'...
,'\alpha = -5^\circ','\alpha = -10^\circ','\alpha = -15^\circ','\alpha = -20^\circ')
ax = gca;
ax.FontSize = 15; % Font Size of 15
How can ensure each data set has a different color?

Réponse acceptée

Michael
Michael le 12 Sep 2022
Create a color map and then give each one a distinct color.
figure;
thecolors = parula(9);
for i = 1:9
plot(rand(5,1),rand(5,1),'Color',thecolors(i,:),'DisplayName',['Line Number = ',num2str(i)]);
hold on;
end
legend('Location','best')
  3 commentaires
Michael
Michael le 13 Sep 2022
@CAM Did this solution work for you? If so, please accept the answer so that others know that it works.
jrz
jrz le 14 Sep 2022
Yes it worked, thanks

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by