Saveas: missing half the figure!?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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');
0 Commenti
Risposte (2)
Shashank Prasanna
il 9 Lug 2013
Try using export_fig, this is a very popular file central submission that makes exporting figures easy and trouble free:
10 Commenti
Shashank Prasanna
il 11 Lug 2013
Unfortunately, we won't be able to help much without something to work with.
Jan
il 20 Feb 2025
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 Commento
Jan
il 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
Vedere anche
Categorie
Scopri di più su Printing and Saving in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!