Changing the legend color
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Najam us Saqib Fraz
am 26 Okt. 2020
Beantwortet: Star Strider
am 26 Okt. 2020
Hello Every one.I am using loop to get 14 plots at one figure.I need to have 14 legends.But the colours for the plot keep repeating.Please look at the picture.Is there any way I can get the separte color for each plot,or can get different nature of plot(dotted lines,dashed lines etc)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/393038/image.jpeg)
0 Kommentare
Akzeptierte Antwort
Star Strider
am 26 Okt. 2020
Try something like this:
y = linspace(0,50,50); % Create Data
v = 1:14; % Number Of Curves
x = sin(v(:)*y*2*pi) + 2*v(:); % Create Data
cm = colormap(jet(numel(v))); % Define Color Map
figure
hold on
for k = 1:numel(v)
plot(x(k,:), y, 'Color',cm(k,:)) % Plot Each Vector According To The Colours In ‘cm’
end
hold off
The colours will not repeat unless you want them to do so. You can use any colormap you want, or you can create your own.
0 Kommentare
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!