同じ座標軸に複数のラ​インがあるとき、それ​ぞれのラインに対して​凡例(legend)​の表示/非表示の設定​はできますか?

33 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2013 年 10 月 25 日
編集済み: MathWorks Support Team 2020 年 6 月 9 日
同じ座標軸に複数のライン(Line オブジェクト)が描画されています。
それぞれのラインに対して、凡例(legend)の表示/非表示の設定はできるか、教えてください。

採用された回答

MathWorks Support Team
MathWorks Support Team 2020 年 6 月 9 日
編集済み: MathWorks Support Team 2020 年 6 月 9 日
Line オブジェクトに紐づいている Annotation オブジェクトの IconDisplayStyle プロパティを使用することで可能です。
下記の例では、赤色の点線の凡例を非表示に設定しています。
t = 1:1/10:10;
y1 = sin(t);
y2 = y1 - 0.5;
y3 = randn(size(t));
% グラフ表示
h1 = plot(t,y1,'b');
hold on
h2 = plot(t,y2,'r:');
h3 = plot(t,y3,'g');
% 赤色のラインの凡例を非表示に設定する
% h2-> 赤色のラインのハンドル
hAnnotation = get(h2,'Annotation');
hLegendEntry = get(hAnnotation,'LegendInformation');
set(hLegendEntry,'IconDisplayStyle','off')
% 凡例の表示
[h,obj] = legend('y1','y3');

その他の回答 (0 件)

カテゴリ

Help Center および File Exchangeライン プロット についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2008a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!