Clear Filters
Clear Filters

Why exporting a figure in pdf changes dimensions of subplots?

5 views (last 30 days)
Hello there. I'm working on my thesis paper. I run into a really annoying problem. I have to export a large number of figures in pdf. The figures are usually 2x2 subplots, each subplot containing square axis 2D maps superimposed by a contour plot.
I report here the code for a single map:
subplot(2,2,1);
% map
imagesc(f,f,real(X(:,:,1)));
% normal axis ydir
set(gca,'ydir','normal')
axis square
hold on;
contour(f,f,real(X(:,:,1)),4,'LineColor', [0 0 0]);
hold off;
set(gca,'xtick',(1.4:.1:1.8));
set(gca,'ytick',(1.4:.1:1.8));
axis([1.3 1.7 1.3 1.7]);
For reference, X is a complex 256x256x10 matrix, f is a 256x1 vector containing the x and y axis (that are equal).
When I make all four subplots repeating the code that I wrote previously and I export with the code reported after I get 4 slightly different sized subplots.
fig = gcf;
fig.PaperUnits = 'centimeters';
fig.PaperSize=[29.7 29.7];
fig.PaperPosition = [1 1 16 16];
print(fig,'ZNPC_DEC_B','-dpdf')
Now. It may seem crazy but I can't stand the difference in size between the generated plots. I need anyways to export my figure in pdf because I need to further elaborate it in a vector graphics software, so please don't propose a bitmap export.
A pdf is attached to the post, so you can get what's the problem.
Thanks in advice and have a nice summer!

Answers (2)

Iñigo Moreno
Iñigo Moreno on 28 Sep 2020
Edited: Iñigo Moreno on 28 Sep 2020
With the newer versions of MATLAB you can use exportgraphics:
exportgraphics(fig,'ZNPC_DEC_B.pdf')

Faiz Gouri
Faiz Gouri on 17 Aug 2017
Did you try using the File Exchange contribution export_fig() which is especially suited to exporting figures for use in publications and presentations, because of the high quality and portability of media produced. It also includes a routine to append multiple files into a pdf

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!