Changing the colour of the lines in a legend.

조회 수: 4 (최근 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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by