Azzera filtri
Azzera filtri

plot legend disappears after resize

25 visualizzazioni (ultimi 30 giorni)
Florian Richter
Florian Richter il 14 Nov 2016
Risposto: Sam McDonald il 16 Nov 2016
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.

Risposte (1)

Sam McDonald
Sam McDonald il 16 Nov 2016
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.

Community Treasure Hunt

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

Start Hunting!

Translated by