Saveas: missing half the figure!?

I have three axes on a single figure. For each one, I manually set the position instead of using subplot. When I save the file using:
saveas(gcf,fileName,'pdf');
the figure saves, the orientation (portrait/landscape) is maintained, and the figure dimensions are preserved, BUT the content of the image is messed up (see attached figure). This only happens sometimes, other times it works just fine doing very similar plotting.
QUESTION: Why is this happening and how do I avoid it without making my life too much more difficult.
Here are some bits and pieces of my code:
% Setup size and orientation to be that of a landscape letter paper
figure(ifig)
set(gcf,'DefaultAxesFontSize',fontsize,'DefaultTextFontSize',fontsize)
set(gcf, 'Units', 'inches', 'PaperPosition', [0,0,11,8.5]);
set(gcf, 'Position', [2 1.5 11 8.5 ]);
set(gcf, 'PaperOrientation','landscape');
% setup axes position
position = [xshift yshift width height1];
axes('units','inches','position',position);
% then I plot using contourf
% now save
fileName = '/path/to/file.pdf';
saveas(gcf,fileName,'pdf');

Antworten (2)

Shashank Prasanna
Shashank Prasanna am 9 Jul. 2013

0 Stimmen

Try using export_fig, this is a very popular file central submission that makes exporting figures easy and trouble free:

10 Kommentare

Check what renderer it is:
get(gcf,'renderer')
Try either of the three: painters, opengl or zbuffers
If they don't work you, there is no harm in using export_fig, its tried and tested and popular. Just keep it in your path.
Kellen
Kellen am 9 Jul. 2013
Thanks, It was using painters. I just tried using export_fig, and it reproduces the problem just as using saveas with painters does.
export_fig file.pdf
I get an image exactly like the one above. Any ideas?
Shashank Prasanna
Shashank Prasanna am 10 Jul. 2013
What happens if you don't set all the properties you set but use the default figure properties? If that doesn't work, we may need to see the fig file or some reproduction steps to try and test it out.
Kellen
Kellen am 10 Jul. 2013
Good idea, just tried it: using default figure properties has the same problems as not setting them... Do you think it has anything to do with setting my axes in inches?
axes('units','inches','position',position);
Shashank Prasanna
Shashank Prasanna am 10 Jul. 2013
Possible. Can you share the fig file or something we can work with?
Kellen
Kellen am 10 Jul. 2013
Unfortunately, no. The data needs to stay with me, I'll try to fake up a dataset tomorrow. Thanks for all of your help so far!
Kellen
Kellen am 11 Jul. 2013
Just for fun, I tried:
print -dpdf /path/to/file.pdf
and that causes the same problems.
Kellen
Kellen am 11 Jul. 2013
Okay. I've linked to a zip file including "fig_test_code.m" which will make the plot with the fake data I've provided. "pageLandscape.m" and "puttext.m" are support files that my code uses, "test.pdf" is the problem figure output, and "data1.mat and data2.mat" are the fake datasets I've created. I tested this all to make sure that it still has the same problem, and it does, so this should be a good starting point. Thank you for your help and let me know if anything else will be helpful to you.
Shashank Prasanna
Shashank Prasanna am 11 Jul. 2013
Unfortunately, we won't be able to help much without something to work with.
Kellen
Kellen am 11 Jul. 2013
Shashank, Thanks again for all of your help. It was a simple fix that a friend caught. I create a new axes for a colorbar, and needed to set 'Visible' to 'Off'. Problem Solved. Thanks again!

Melden Sie sich an, um zu kommentieren.

Jan
Jan am 20 Feb. 2025

0 Stimmen

I have this same problem. Unfortunately the fix you describe is not clear to me.
In my plot (single axes, with axes labels, tile and legend), I annotate some data points and add text sing the text() function both inside the axes and in the margin to the right of the axes.
When I use the GUI to save the (full screen) image, the results are as expected, but when using saveas() the image is cut to about 2/3 of the size in both dimentions. The top-left corner is preserved, the lower-right corner is missing. Also the legend overlaps my plotted data, as if the window was much smaller when the function call was made.
Are there some preferences that can be set for this function?

1 Kommentar

Jan
Jan am 20 Feb. 2025
Got it to work with exportgraphics() and png file type. Not with e.g., emf.
https://nl.mathworks.com/help/matlab/creating_plots/save-figure-at-specific-size-and-resolution.html

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Printing and Saving finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 9 Jul. 2013

Kommentiert:

Jan
am 20 Feb. 2025

Community Treasure Hunt

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

Start Hunting!

Translated by