Changing plot line colour with multiple data sets

3 次查看(过去 30 天)
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?

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by