MATLAB Answers


Save figure as seen on screen?

Asked by C
on 25 Jan 2013
Latest activity Commented on by James Ryan
on 17 Sep 2016

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!


2 Answers

Answer by Jan Simon
on 25 Jan 2013

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

  1 Comment


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

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.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!