Different colors between plot and legend
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ivan Mich
am 2 Jun. 2020
Bearbeitet: Ivan Mich
am 18 Jun. 2020
Hi,
Does anybody knows why there are different colors between plot lines and legend ?
4 Kommentare
Akzeptierte Antwort
Bjorn Gustavsson
am 2 Jun. 2020
Ivan, when you plot multiple lines like this and want to put a legend into the figure (or want to modify the lines)
use the plot-handles returned by plot:
x = 0:10;
y = randn(5,numel(x));
ph1 = plot(x,y(1:2,:),'-','linewidth',2);
hold on
ph2 = plot(x,y(3:5,:),'--')
legend([ph1(:);ph2(:)],'1','2','3','4','5')
HTH
4 Kommentare
Bjorn Gustavsson
am 18 Jun. 2020
Ivan, you could do something like this programatically:
for iFiles = numel(np)
legstr{iFiles} = [np(iFiles).name,' M']; % or with sprintf('%s M',np(iFiles).name);
end
legend([ph1(:);ph2(:)],legstr{:})
When I've come that far I usually become pragmaticall and start to hard-code the legend-strings, it comes down to how many times you will re-run this with other labelings...
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Legend 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!