How to change the color of the line in the legend of the figure?

19 ビュー (過去 30 日間)
Lucy
Lucy 2024 年 11 月 28 日 16:04
回答済み: Star Strider 2024 年 11 月 28 日 16:22
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.

採用された回答

Star Strider
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)
y = 1000×5
1.0000 2.0000 3.0000 4.0000 5.0000 1.0063 2.0377 3.0691 4.1005 5.1317 1.0126 2.0754 3.1379 4.1999 5.2611 1.0189 2.1130 3.2061 4.2973 5.3859 1.0252 2.1504 3.2732 4.3917 5.5041 1.0314 2.1876 3.3391 4.4822 5.6134 1.0377 2.2245 3.4033 4.5678 5.7121 1.0440 2.2611 3.4656 4.6476 5.7984 1.0503 2.2973 3.5256 4.7209 5.8707 1.0566 2.3331 3.5832 4.7868 5.9279
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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 件)

カテゴリ

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