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

21 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Scott MacKenzie
Scott MacKenzie le 9 Juin 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 commentaire
Scott MacKenzie
Scott MacKenzie le 9 Juin 2021
Modifié(e) : John Kelly le 16 Déc 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Plot Customization dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by