How can I change legend colors if I have multiple graphs of the same color?
2 ビュー (過去 30 日間)
古いコメントを表示
I'm plotting 10 funtcions in the same graph, 5 of one type in red and 5 of another type in blue.
I would like to create a legend where there is a red line that says "Type1" and a blue line that says "Type2".
I didn't find a way to do that since the lengend is expecting 10 names, and if I put only two of them, those are both red.
0 件のコメント
採用された回答
Sachin Shrestha
2016 年 6 月 11 日
Hi Leonardo,
You may specify the handles of the plots for which you want to have the legend. In your case, you may specify handles, one for red line and another for blue line and generate legends for those only. For instance:
handle1=plot(1:10,'r'); % define handle for one of the red lines
hold on;
plot(1:2:20,'r');
plot(1:3:30,'r');
plot(1:4:40,'r');
plot(1:5:50,'r');
handle2=plot(3:10,'b'); % define handle for one of the blue lines
plot(3:2:20,'b');
plot(3:3:30,'b');
plot(3:4:40,'b');
plot(3:5:50,'b');
legend([handle1 handle2],{'type1','type2'}); % define legend for plots related to handles
Hope this helps. Good Luck!
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!