How do I show only two colors in my Legend?

14 ビュー (過去 30 日間)
Heather Spain
Heather Spain 2020 年 5 月 26 日
コメント済み: KALYAN ACHARJYA 2020 年 5 月 26 日
I only want to label in my legend the moon and the earth, so how do I get rid of the rest of the colours? Is it possible to only show the earth (yellow) and the Moon (green) in the legend?
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 5 月 26 日
data1=plot(earth_data);
plot others..
data2=plot(moon_data);
legend([data1,data2],'Earth','Moon');

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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 5 月 26 日
You can use the handle returned by plot() with legend() to only show specific legends. For example
hold on;
p(1) = plot(rand(1,10));
p(2) = plot(rand(1,10));
p(3) = plot(rand(1,10));
p(4) = plot(rand(1,10));
p(5) = plot(rand(1,10));
legend(p([3 5]), {'legend3', 'legend5'});

カテゴリ

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