(Answers Dev) Restored edit
the colors red, blue, yellow repeated again in my plot, how I can give each curve in the plot different color
27 views (last 30 days)
Show older comments
Matthew Worker
on 9 Jun 2021
Edited: John Kelly
on 16 Dec 2021
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
Accepted Answer
Scott MacKenzie
on 9 Jun 2021
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 Comment
Scott MacKenzie
on 9 Jun 2021
Edited: John Kelly
on 16 Dec 2021
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
More Answers (0)
See Also
Categories
Find more on Plot Customization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!