Changing plot line colour with multiple data sets

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Michael
Michael il 12 Set 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 Commenti
Michael
Michael il 13 Set 2022
@CAM Did this solution work for you? If so, please accept the answer so that others know that it works.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by