How do I plot one legend item for multiple plots?
Afficher commentaires plus anciens
How can I label multiple plots with one legend item?
For example, I have 5 different plots and I want my legend to only contain "random plot is even" and "random plot is odd" and the plots with the same label should have the same colour. The only solution I found that comes close to it is below. The problem is that the labeling of the plots occurs multiple times and the plots with the same label have different colours.
clear all; close all;
figure; hold on;
for iter =1:5
rand_iter = rand(1,5);
plot(rand_iter)
if(mod(iter,2))
legend_iter{iter} = sprintf(['random plot is ', 'odd']);
else
legend_iter{iter} = sprintf(['random plot is ', 'even']);
end
end
legend(legend_iter)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Legend dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
