凡例に追加せずに、グラフ内に線を引く

59 views (last 30 days)
Mamoru Mabuchi
Mamoru Mabuchi on 17 Jun 2020
Answered: Mamoru Mabuchi on 21 Jun 2020
グラフ内に線を引きたいのですが、勝手に凡例に追加されてしまいます。
凡例に追加せずに、線だけをプロットする方法を教えてください。
x=1:10;
y=sin(x);
plot(x,y)
legend('sin')
xline(4) % 線だけひきたい

Answers (3)

michio
michio on 18 Jun 2020
x=1:10;
y=sin(x);
plot(x,y)
legend('sin')
xline(4) % 線だけひきたい
と実行したときに凡例として 'sin' に加えて 'data1' が出てきてしまうのが問題ということですね。
例えば特定の線にだけ凡例を付ける場合は、その線のオブジェクト(下記 h1 と h2)にだけ凡例を付ける・・という呼び出し方があります。
x=1:10;
y=sin(x);
h1 = plot(x,y);
h2 = xline(4);
legend(h1, 'sin')
ただ、この後にさらに xline(5) と実行するとまた新たに判例が追加されてしまいます・・。ですので、プロットするものが最後まで終わった時に legend を実行しなければいけないという点は、多少不便ですね。
次は、描いた線のプロパティを変更する方法です。以下でも紹介されています。
具体的には、
x=1:10;
y=sin(x);
plot(x,y)
legend('sin')
h2 = xline(4)
h2.HandleVisibility = 'off';
という形で xline で描いた線のオブジェクトの持つ、'HandleVisiblity''off' にすることで凡例には反映されなくなります。
他にもよいやり方があればコメントください。参考になりましたら。

Kenta
Kenta on 18 Jun 2020
legend('sin')
を消去したらいかがでしょうか?

Mamoru Mabuchi
Mamoru Mabuchi on 21 Jun 2020
解決しました。ご回答ありがとうございました。

Categories

Find more on 2 次元および 3 次元プロット in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!