全て同じ色のラインプロットのうち、一つだけの凡例を設定するにはどうしたら良いですか?
39 views (last 30 days)
Show older comments
次のようなコードを実行したとき、figure に3本のプロットが描かれます。
plot(1:10,sin(1:10),'r');
hold on
plot(1:10,cos(1:10),'r');
plot(1:10,sin(1:10) + sin(1:10),'b');
そのうち2本は赤で、他の線は青です。Figure に凡例を付けた際、凡例の枠内に、data1、data2 とラベル付された赤の線が2本と data3 とラベル付けされた青の線が出ました。しかし、赤の線を1本にして data1、青の線は data2 のようにラベル付けしたいと考えています。この重複した凡例を消す方法を教えてください。
Accepted Answer
MathWorks Support Team
on 25 May 2012
赤の線を data1 ように1本だけ表示し (3本の線のうち、2本の線を示す) 、青の線1本を data2 とラベル付するには、凡例に表示したいラインオブジェクトのハンドルのみを使用して次のサンプルコードを参考にしてください。
h(1) = plot(1:10,sin(1:10),'r');
hold on
h(2) = plot(1:10,cos(1:10),'r');
h(3) = plot(1:10,cos(1:10) + sin(1:10),'b');
legend(h([1,3]),{'data1','data2'})
0 Comments
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!