Hi,
Does anybody knows why there are different colors between plot lines and legend ?

댓글 수: 4

Paresh yeole
Paresh yeole 2020년 6월 2일
please elaborate.
Ivan Mich
Ivan Mich 2020년 6월 2일
Look, I am plotting some line using a loop. The point is that these lines has totally different color with the legend colors.
KSSV
KSSV 2020년 6월 2일
We cannot comment/ help unless your code is shown to us.
Ivan Mich
Ivan Mich 2020년 6월 2일
D=table(Y,X,meanD)
writetable(D,'D.txt')
hold on
plot(Y,X,'o','DisplayName','0.3')
plot(Y,meanD,'*','DisplayName','0.3')
legend

댓글을 달려면 로그인하십시오.

 채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2020년 6월 2일

0 개 추천

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

Ivan Mich
Ivan Mich 2020년 6월 2일
편집: Ivan Mich 2020년 6월 2일
Thank you!!
Ivan Mich
Ivan Mich 2020년 6월 18일
편집: Ivan Mich 2020년 6월 18일
Excuse me , if I would like to add a specific letter in the legend what I should do ?
I am using a loop in order to "pick" the names for the legend and I use these commands:
np=filenames
legend ([ph1(:);ph2(:)],np{1:n} )
np has these names:
TEST1, TEST2, TEST3.
I would like to put a character, eg letter "M", in the "legend" command, in order to my final legend in the plot to have:
TEST1 M
TEST2 M
TEST3 M
Could you help me?
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...
Ivan Mich
Ivan Mich 2020년 6월 18일
편집: Ivan Mich 2020년 6월 18일
I have tried your solution but it shows me these:
Error using legend
Inputs must be the same size or either one can be a scalar.
What I have to do in order to solve it?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2020년 6월 2일

편집:

2020년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by