Bodeplot axes automatically rescale after printing

1 view (last 30 days)
I have the following code to plot a bodeplot of a system and store this bodeplot as pdf and png:
%% ------------------------------------------------------------------------
figure;
fig1 = gcf;
fig1.Units = 'centimeters';
fig1.Position = FigPos;
fig1.Color = [1 1 1];
bodeplot(sysa, w, opts);
hold on
bodeplot(sysb, w, opts);
bodeplot(sysc, w, opts);
grid on;
axes = findall(fig1, 'type', 'axes');
AXMag = axes(3);
AXMag.Title.String = [];
AXMag.YLabel.String = 'Magnitude in dB';
AXMag.XTick = AXMag.XTick;
AXPhs = axes(2);
AXPhs.YLabel.String = 'Phase in deg.';
AXPhs.XTick = AXPhs.XTick;
AXPhs.XTickLabel = mat2cell(AXPhs.XTick/1e3,1);
AXPhs.XLabel.String = 'Frequency in kHz';
AXTit = axes(1);
AXTit.Title.String = [];
AXTit.XLabel.String = [];
TIMag = AXMag.TightInset;
TIPhs = AXPhs.TightInset;
x0 = max([TIMag(1) TIPhs(1)]);
y0 = TIPhs(2);
wax = 1-x0-max([TIMag(3) TIPhs(3)]);
hax = (1-y0 - TIMag(4) - BodeDistance)/2;
AXMag.Position = [x0 y0+hax+BodeDistance wax hax];
AXPhs.Position = [x0 y0 wax hax];
drawnow;
print(fig1, '-dpng','-r600', [FigPath, FigName, 'BodeRef', '.png']);
set(fig1,'PaperSize', [fig1.Position(3) fig1.Position(4)]);
set(fig1,'PaperPosition', [0 0 fig1.Position(3) fig1.Position(4)]);
set(fig1,'Renderer','painters');
print(fig1,'-dpdf', [FigPath, FigName, 'BodeRef', '.pdf']);
The code works fine so far, however, there is some strange effect after the figure is saved: the axes of the bodeplot automatically rescale without any reason after some (a few seconds) time.
Originally, the code generates this picture:
And after waiting (without doing anything, Matlab doesn't execute any code anymore, the program terminates after the figure is printed), suddenly this happens (you have to be fast enough to take the screenshot before the picture changes):
This is extremely annoying, especially since I want to reuse the content of the figure by copying it into another one (combining several plots). How to stop Matlab from changing the size (and why is Matlab doing it at all)?

Answers (0)

Categories

Find more on Interactive Control and Callbacks 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!