MATLAB Answers


Save figure as seen on screen?

Asked by C
on 25 Jan 2013
Latest activity Commented on by Amir Mazouchi on 30 Oct 2017 at 8:20

I would like to save a figure to png format exactly the same as seen on the screen. I searched the web and found:

set(gcf,'PaperPositionMode','auto'); saveas(gcf,[Filename '.png']);

that supposed to save the figure the same size, but it actually changed the size from 1200x600 to 1875x938, huh?

I also tried setting ‘PaperPosition’ and got the same size 1200x600, but the fonts in the saved figure became much larger compared to on screen and covered up parts of the graph.

If I use the "save" button in the figure window then it saves the figure as seen on the screen without a problem, but I would like to be able to do it programmatically if possible.

Please help. Thanks!


Log in to comment.

2 Answers

Answer by Jan Simon
on 25 Jan 2013

img = getframe(gcf);
imwrite(img.cdata, [FileName, '.png']);



It's really odd that none of the Save as or Export options on the figure window seem to support this.

use gca instead of gcf to get rid of all margins.

Log in to comment.

Answer by John Petersen on 25 Jan 2013

It's the same ratio at least. You may want to look at using export_fig() which you can download from the file exchange. This will preserve the figure size.

  1 Comment

As mentioned in the FAQ: While you're reading that C, might as well look over the rest of the FAQ also.

Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today