plot legend disappears after resize

6 ビュー (過去 30 日間)
Florian Richter
Florian Richter 2016 年 11 月 14 日
回答済み: Sam McDonald 2016 年 11 月 16 日
the legend of my bodeplot disappears after i resize the figure with my mouse
b = [0 2 3; 1 2 1];
a = [1 0.4 1];
[A,B,C,D] = tf2ss(b,a);
statespace = ss(A,B,C,D) ;
f = figure;
p = bodeplot(statespace(1,1));
setoptions(p,'FreqUnits','Hz','PhaseVisible','off');
legend('test','Location','southwest');
set(f, 'ResizeFcn', @(varargin) legend('test','Location','southwest'))
solves the problem but maybe there is a better solution.

回答 (1 件)

Sam McDonald
Sam McDonald 2016 年 11 月 16 日
A "bodeplot" creates more than one axes and when calling "legend" without specifying the parent axes, MATLAB takes the last active axes which might be an invisible one leading to undesired behavior. Overall it is the best to specify the axes as input to which the legend refers, e.g.
legend(findall(gcf,'type','axes','visible','on'),'test','Location','southwest');
This will keep the legend visible when resizing the figure.

カテゴリ

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