
凡例(legend) の自動更新を行わないように設定できますか?
20 views (last 30 days)
Show older comments
MathWorks Support Team
on 2 Apr 2018
Edited: MathWorks Support Team
on 3 Apr 2018
R2016b 以前と、R2017a 以降のバージョンでは、legend 関数の実行結果が異なります。
例えば、以下のコードを実行すると、R2016b までは 1 本目のラインの凡例だけが表示されていましたが、R2017a 以降では、2 番目に追加したラインの凡例も 'data1' という名前で自動的に表示されます。
figure(1)
plot(1:10,rand(1,10))
legend('Line1') % 凡例の表示
hold on
plot(1:10,rand(1,10),'x') % このコマンドで 'data1' の凡例が追加される
R2016b 以前のバージョンと同様に、凡例の表示が自動更新されないように設定する方法を教えてください。
Accepted Answer
MathWorks Support Team
on 3 Apr 2018
legend 関数は、R2017a より Axes のアップデートに対応するよう、仕様変更されています。
例えば、Axes 上に plot でラインが表示されると、自動的に凡例にもそのラインが追加されます。
この自動アップデートを行いたくない場合には、以下のように、legend 関数において、'AutoUpdate' プロパティを 'off' に設定します。
legend('Line1','AutoUpdate','off');
Figure 全体に対して、凡例の自動アップデートを無効にしたい場合には、Figure の 'defaultLegendAutoUpdate' プロパティを 'off' に設定します。
figure(1);
set(gcf,'defaultLegendAutoUpdate','off')
また、個々のオブジェクトについて、凡例の表示・非表示を設定したい場合には、オブジェクト下の Annotation のプロパティで制御可能です。
p = plot(1:10,'DisplayName','Line Chart');
hold on
s = stem(1:10,'DisplayName','Stem Chart');
hold off
s.Annotation.LegendInformation.IconDisplayStyle = 'off'; % step プロットの凡例の非表示設定
legend('show') % 凡例の表示

関連する内容が以下の URL からご覧いただけます。
・R2017a Release Notes
・Line オブジェクト:Annotation プロパティ
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!