Axis labels are cut off when saving figure

Consider the following MWE with produces a figure:
clear
close all
fig1 = figure(1);
set(gca,'xscale','log')
set(gca,'yscale','log')
xlabel('Frequency (Hz)')
ylabel('Amplitude (dB)')
set(gca,'FontUnits','points',...
'FontWeight','normal',...
'FontSize',10,...
'FontName','Times',...
'Units','normalized');
PaperW = 16;
PaperH = 7.5;
fig1.Units = 'centimeters';
fig1.Position = [20 10 PaperW PaperH];
fig1.PaperUnits = 'centimeters';
fig1.PaperPosition = [0 0 PaperW PaperH];
print(fig1,'fig1.png','-dpng','-r300')
I'm trying to save this as a .png file using print. Additionally, I want the saved image to be 16cm by 7.5cm. I specified this using variables called PaperW and PaperH (the width and height).
The problem is, the bottom of the xlabel text is cut off. Why is this happening? And how can I solve this problem?
Zoomed in on the xlabel. Notice how the bottom of the q and y are cut off.

Respuestas (1)

Myles
Myles el 16 de Mayo de 2018
One solution has been found. The trick is to offset the y coordinate (by a small amount) and then offset the height by the same amount.
pos = get(gca, 'Position');
set(gca, 'Position', [pos(1) pos(2)+0.01 pos(3) pos(4)-0.01]);

1 comentario

Mike Borrello
Mike Borrello el 16 de Jun. de 2018
No this doesn't work, at least for plots created by bode. It just squeezes the phase plot, but the xlabel left in its original position after executing saveas.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Exploration en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Mayo de 2018

Comentada:

el 16 de Jun. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by