Legend not using correct colors

191 ビュー (過去 30 日間)
Nazmus Saadat
Nazmus Saadat 2020 年 1 月 5 日
コメント済み: Nazmus Saadat 2020 年 1 月 6 日
I seem to not be able to get legend to work properly. I have 3 plots, 2 of which I have specified colors for. But when attempting to create a legend for all 3, the colors I specified (red and green) both appear red. I have included the code used to create the figure, the figure itself and a MAT file containing the variables used to make the plot.
%%
figure
hold on
plot(k,avg_lowerbound)
plot(k,zeros(max_k)+avg_ibp_lowerbound,'r')
plot(k,zeros(max_k)+avg_lbp_lowerbound,'g')
legend("Random inputs", "I.B.P", "L.B.P")
xlabel('k')
ylabel('Average lower bound')
%%

採用された回答

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 1 月 5 日
Your zeros(max_k) was a matrix, so each plot command made many plots and the legends went to the wrong place. Making it only a vector solves your problem
figure
hold on
plot(k,avg_lowerbound)
plot(k,zeros(max_k,1)+avg_ibp_lowerbound,'r')
plot(k,zeros(max_k,1)+avg_lbp_lowerbound,'g')
legend("Random inputs", "I.B.P", "L.B.P")
xlabel('k')
ylabel('Average lower bound')
  1 件のコメント
Nazmus Saadat
Nazmus Saadat 2020 年 1 月 6 日
Ah thanks! I can't believe I didn't spot that.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by