Changing the colour of the lines in a legend.

11 ビュー (過去 30 日間)
Phillip Smith
Phillip Smith 2020 年 3 月 30 日
回答済み: Peng Li 2020 年 4 月 2 日
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 件のコメント
Abhisek Pradhan
Abhisek Pradhan 2020 年 4 月 2 日
Can you provide your data and let me see if i can reproduce it.

サインインしてコメントする。

回答 (1 件)

Peng Li
Peng Li 2020 年 4 月 2 日
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');

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by