Why is not the second tag in the legend?

1 回表示 (過去 30 日間)
Tony Castillo
Tony Castillo 2022 年 5 月 4 日
コメント済み: Voss 2022 年 5 月 5 日
Dear all,
I have been attempting to set the two legends at the boxplot, but there might be something wrong in my code since the second tag "mean" does not appear on the final plot, do you mind cheking this out?
figure
boxplot([SOC_, SOC_Max, SOC_mean], 'Labels',{'SOC','SOC(Max)','SOC(mean)'})
hold on
meanSOCs=mean([SOC_, SOC_Max, SOC_mean]);
plot(meanSOCs,'-o')
ylabel('State of charge (%)')
grid on
hold off
legend(["Data", "mean"])
Best regards

採用された回答

Voss
Voss 2022 年 5 月 4 日
Store the line handles returned from boxplot and plot and use them to explicitly tell legend which lines to use:
SOC_ = randn(10,1);
SOC_Max = randn(10,1);
SOC_mean = randn(10,1);
figure
h_bp = boxplot([SOC_, SOC_Max, SOC_mean], 'Labels',{'SOC','SOC(Max)','SOC(mean)'});
hold on
meanSOCs=mean([SOC_, SOC_Max, SOC_mean]);
h_m = plot(meanSOCs,'-o');
ylabel('State of charge (%)')
grid on
hold off
legend([h_bp(5,1) h_m],["Data", "mean"]) % using a blue box line h_bp(5,1)
  2 件のコメント
Tony Castillo
Tony Castillo 2022 年 5 月 5 日
Thank you Sir
Voss
Voss 2022 年 5 月 5 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by