Changing the colour of the lines in a legend.
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hey everyone,
I've seen this asked a few times but i can't find anything that actiually helps me.
I have a matrix with 250 columns. There's 5 goups of 50 columns that make up the whole matrix. Now I've plotted this and have managed to plot each group in its own colour i.e. when columns 1:50 are plotted they're red, columns 51:100 are plotted blue etc. The code i used to plot the different colours is here;
p = plot(Inf_Beta);
set(p(1:50), 'Color', 'red');
set(p(51:100), 'Color', 'blue');
set(p(101:150), 'Color', 'yellow');
set(p(151:200), 'Color', 'green');
set(p(201:250), 'Color', 'magenta');
With the current legend that I'm using, as below
legend({'beta = 0.2','beta = 0.4','beta = 0.6','beta = 0.8','beta = 1'},'Fontsize',15,'Location','southeast');
All the indicator lines on the legend are red. I realise this is because what the legend is saying is that the first 5 lines are the 5 beta values, and since the first 5 lines are red, the indicator lines in the legend are red.
What i need is one line for each of the 5 values of beta and they're corresponding colour. If anyone can help that'll be greatly appreciated because i think i'm losing my mind.
Phill
1 Kommentar
Antworten (1)
Peng Li
am 2 Apr. 2020
You have 250 lines and with the legend function you are actually only showing the legend for the first 5 lines, which are red based on your setting. Have a try
legend(p([1 51 101 151 201]), {'beta = 0.2','beta = 0.4','beta = 0.6','beta = 0.8','beta = 1'},'Fontsize',15,'Location','southeast');
0 Kommentare
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!