How to change the color of the line in the legend of the figure?
19 ビュー (過去 30 日間)
古いコメントを表示
How to change the color of the line in the legend of the figure? I have changed the color of the curves in my figure for several times but the line color did not change correspondingly with them.
0 件のコメント
採用された回答
Star Strider
2024 年 11 月 28 日 16:22
It would help to have your code and data.
The legend entries correspond to the lines being plotted, and if there are more than one line, this can cause ptoblems.
You may need to speciifically reference each separate plot call.
Example —
x = linspace(0, 1, 1E+3).';
y = sin(2*pi*x*(1:5:25)) + (1:5)
figure
plot(x, y(:,1:3), 'b')
hold on
plot(x, y(:,4:5), 'r')
hold off
grid
legend('y_1','y_2') % No Specific References
figure
hp1 = plot(x, y(:,1:3), 'b');
hold on
hp2 = plot(x, y(:,4:5), 'r');
hold off
grid
legend([hp1(1) hp2(1)], 'y_1','y_2') % With Specific References
.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!