How to correct the order of colours while using legend command?

1 回表示 (過去 30 日間)
Paromita Bhattacharjee
Paromita Bhattacharjee 2015 年 10 月 15 日
回答済み: Image Analyst 2015 年 10 月 15 日
I have a plot for 6 different line equations. I have plotted these with 6 different color, but in the plot, in legend location the colors are coming out of the order in which they were plotted. Please help if anyone knows how to correct this problem.
  2 件のコメント
Image Analyst
Image Analyst 2015 年 10 月 15 日
Did you plot a 2D matrix, or did you call plot 6 different times with 6 different vectors?
Paromita Bhattacharjee
Paromita Bhattacharjee 2015 年 10 月 15 日
To be more specific, if I have- plot(x,y1,'k', x,y2,'b', x,y3,'m'); then using legend as- legend('eq1', 'eq2', 'eq3'); should indicate black color as eq1, blue as eq2 and magenta as eq3. But it isn't.

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

回答 (2 件)

Thorsten
Thorsten 2015 年 10 月 15 日
This is the expected behavior of the legend function. If you want another order, the simplest way is to change the order of plotting the equations. If you do not tell us what you want to achieve, we cannot guess how to 'correct' the correct behavior of a function.
  2 件のコメント
Paromita Bhattacharjee
Paromita Bhattacharjee 2015 年 10 月 15 日
編集済み: Image Analyst 2015 年 10 月 15 日
To be more specific, if I have-
plot(x,y1,'k', x,y2,'b', x,y3,'m');
then using legend as-
legend('eq1', 'eq2', 'eq3');
should indicate black color as eq1, blue as eq2 and magenta as eq3. But it isn't.
Thorsten
Thorsten 2015 年 10 月 15 日
編集済み: Thorsten 2015 年 10 月 15 日
For me this works as expected:
x = 1:100; y1 = x; y2 =2*x; y3 = 3*x;plot(x,y1,'k', x,y2,'b', x,y3,'m')
legend('eq1', 'eq2', 'eq3')

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


Image Analyst
Image Analyst 2015 年 10 月 15 日
It works fine for me. I'm using R2015b. What version are you using? Can you post a screenshot?

カテゴリ

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