필터 지우기
필터 지우기

Legend doesn't match plot

조회 수: 21 (최근 30일)
LM
LM 2021년 3월 17일
댓글: LM 2021년 3월 17일
Hello, my legend color doesn't match the color of my plot. I need two diffentent colors in my legend. I have already searched the other questions asked, but none of them seem to work for me.
figure
hold on
% P(1) = plot(x1,a1,'g.',x2,b1,'g.',x3,c1,'g.',x4,d1,'g.','DisplayName','a')
plot(x1,a1,'g.',x2,b1,'g.',x3,c1,'g.',x4,d1,'g.');
errH1 = errorbar(mean(x1), mean(a1), error_LG(1,Rauheitskennwert),'g+');
errH1.LineWidth = 1.2;
errH2 = errorbar(mean(x2), mean(b1), error_LS(1,Rauheitskennwert),'g+');
errH2.LineWidth = 1.2;
errH3 = errorbar(mean(x3), mean(c1), error_LgR(1,Rauheitskennwert),'g+');
errH3.LineWidth = 1.2;
errH4 = errorbar(mean(x4), mean(d1), error_RG(1,Rauheitskennwert),'g+');
errH4.LineWidth = 1.2;
xlim([0.5 4.5])
plot(x1,a_Filter,'.b',x2,b_Filter,'.b',x3,c_Filter,'.b',x4,d_Filter,'.b');
% P(2) = plot(3,a_Filter,'.b',3,b_Filter,'.b',3,c_Filter,'.b',3,d_Filter,'.b','DisplayName','b')
errH6 = errorbar(mean(x1), mean(a_Filter), std(a_Filter),'b+');
errH6.LineWidth = 1.2;
errH7 = errorbar(mean(x2), mean(b_Filter), std(b_Filter),'b+');
errH7.LineWidth = 1.2;
errH8 = errorbar(mean(x3), mean(c_Filter), std(c_Filter),'b+');
errH8.LineWidth = 1.2;
errH9 = errorbar(mean(x4), mean(d_Filter), std(d_Filter),'b+');
errH9.LineWidth = 1.2;
% legendNames = ['a','b'];
% legend(P)
legend('a','b')
  댓글 수: 2
Çağlar  İŞLEK
Çağlar İŞLEK 2021년 3월 17일
Hi, Please share your output plot, I will look into it.
LM
LM 2021년 3월 17일
Hey, thanks for your answer. You should be able to view it below my name. It is called 'Screenshot 2021-03-17 105128.png'. But Roy Kadesh's answer has already solved my problem. Thanks a lot for your willing to help me though.

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

채택된 답변

Roy Kadesh
Roy Kadesh 2021년 3월 17일
You did not explicitly state the handles for the legend, so Matlab uses the first two, which happen to be both green, since your plot call returns 4 objects.
%these are the required edits:
h_green=plot(x1,a1,'g.',x2,b1,'g.',x3,c1,'g.',x4,d1,'g.');
h_blue=plot(x1,a_Filter,'.b',x2,b_Filter,'.b',x3,c_Filter,'.b',x4,d_Filter,'.b');
legend([h_green(1) h_blue(1)],{'a','b'})
  댓글 수: 1
LM
LM 2021년 3월 17일
Thanks a lot for your help and explanation. That's exactly what i was doing wrong.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by