(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
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matthew Worker
am 9 Jun. 2021
Bearbeitet: John Kelly
am 16 Dez. 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
Akzeptierte Antwort
Scott MacKenzie
am 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 Kommentar
Scott MacKenzie
am 9 Jun. 2021
Bearbeitet: John Kelly
am 16 Dez. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Plot Customization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!