フィルターのクリア

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 Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by