MATLAB Answers

C
0

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!

  0 Comments

Log in to comment.

2 Answers

Answer by Jan Simon
on 25 Jan 2013

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

  1 Comment

Perfect.

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

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: http://matlab.wikia.com/wiki/FAQ#How_do_I_save_my_figure.2C_axes.2C_or_image.3F_I.27m_having_trouble_with_the_built_in_MATLAB_functions.. While you're reading that C, might as well look over the rest of the FAQ also.

Log in to comment.


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!