plot legend disappears after resize

10 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by