change the color of data in legend

96 ビュー (過去 30 日間)
Hassan
Hassan 2011 年 6 月 21 日
コメント済み: aerothermal 2016 年 8 月 31 日
I have 3 plots on the same figure but legend doesn't show the right color for each plot.
y=1:10;
color_=['r', 'b'];
for i=1:2
if i==1
j=1;
elseif i==2
j=6;
end
plot(y(j:j+4),color_(i));
hold on
plot([0 10],[5 5],'g');
end
legend('plot1','plot2','line');

採用された回答

Walter Roberson
Walter Roberson 2011 年 6 月 21 日
h1 = plot(x1,y1,'r');
hold on
h2 = plot(x2,y2,'b');
legend([h1,h2],'plot1','plot2')
The line color used for legend() will be the same as the line color used on the graph.
  2 件のコメント
Hassan
Hassan 2011 年 6 月 21 日
thanks Walter. sorry I think my question wasn't clear I changed it. could u please look at it.
Hassan
Hassan 2011 年 6 月 28 日
sice i was using a loop, i did this thing:
h=zeros(2);
colors=['r','g']
for i=1:2
h(i)=plot(x1,y1,colors(i))
legend([h(1),h(2)],'plot1','plot2')
end

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

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2011 年 6 月 21 日
Follow this post to change the color of the legend.
  14 件のコメント
Hassan
Hassan 2011 年 6 月 21 日
thanks Walter for the help.
aerothermal
aerothermal 2016 年 8 月 31 日

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

カテゴリ

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