the colors red, blue, yellow repeated again in my plot, how I can give each curve in the plot different color

27 次查看(过去 30 天)
clc;
clear;
K=1:30;
for i=1:10
C_T=i*log(K);
plot_T = plot(K,C_T,'-O','LineWidth',2);
hold on
grid on
title('Total Capacity of the System')
xlabel('Number of Users')
ylabel('Total Capacity (bit/s/Hz)')
legend
end

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-6-9
One way is to specify a different color in each call to the plot function:
K=1:30;
for i=1:10
C_T=i*log(K);
plot_T = plot(K,C_T,'-O','color', rand(1,3), 'LineWidth',2); % use custom color
hold on
grid on
title('Total Capacity of the System')
xlabel('Number of Users')
ylabel('Total Capacity (bit/s/Hz)')
legend
end
  1 个评论
Scott MacKenzie
Scott MacKenzie 2021-6-9
编辑:John Kelly 2021-12-16
Below is some modified code that increases the number of colors from 7 to 10. The additional colors are random, but you can set them to particular colors if you wish.
ax = gca;
ax.ColorOrder(8:10,:) = rand(3,3); % increase from 7 to 10 colors
hold on;
K=1:30;
for i=1:10
C_T=i*log(K);
plot_T = plot(K,C_T, '-O', 'LineWidth', 2);
hold on
grid on
title('Total Capacity of the System')
xlabel('Number of Users')
ylabel('Total Capacity (bit/s/Hz)')
legend
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Plot Customization 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by