How to change color of lines on legend?
251 ビュー (過去 30 日間)
古いコメントを表示
Is there any way to change the color of lines in the legend AFTER plotting the graph(like using Edit\axes properties)?
5 件のコメント
採用された回答
Mahdi Torabi
2018 年 7 月 14 日
編集済み: Matt J
2018 年 7 月 14 日
2 件のコメント
Matt J
2018 年 7 月 14 日
This gives an error,
Error using legend>process_inputs (line 554)
Invalid argument. Type 'help legend' for more information.
Error in legend>make_legend (line 306)
[autoupdate,orient,location,position,children,listen,strings,propargs] = process_inputs(ha,argin); %#ok
Error in legend (line 259)
make_legend(ha,args(arg:end),version);
Walter Roberson
2018 年 7 月 15 日
Turns out you just need
hold on
to be in effect, as otherwise the second plot() clears the axes.
その他の回答 (1 件)
Matt J
2018 年 7 月 14 日
編集済み: Matt J
2018 年 7 月 14 日
This might be what Walter meant,
t=linspace(0,1,10);
L(1:2) = plot(t,exp(-t), 'r--',nan,nan,'k--');hold on
L(3:4) = plot(t,1-exp(-t), 'g^-',nan,nan,'m^-'); hold off
legend(L([2,4]), 'Red','Green')

2 件のコメント
Walter Roberson
2020 年 5 月 1 日
plot(nan,nan) with appropriate line style and color, once for each different thing you want to appear in the legend, recording the handle that is returned. Then when you call legend(), pass that array of handles in as the first parameter to legend()
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!