Save figure as seen on screen?
Ältere Kommentare anzeigen
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!
Antworten (2)
Jan
am 25 Jan. 2013
img = getframe(gcf);
imwrite(img.cdata, [FileName, '.png']);
5 Kommentare
James Ryan
am 17 Sep. 2016
Perfect.
It's really odd that none of the Save as or Export options on the figure window seem to support this.
Amir Mazouchi
am 30 Okt. 2017
use gca instead of gcf to get rid of all margins.
Martim Zurita
am 1 Okt. 2021
Jan (or anyone who knows the answer), is there a way to "save figure as seen on screen" in .pdf or .eps format?
When I try to do something like
img = getframe(gcf);
imwrite(img.cdata, [FileName, '.eps']);
I get the error "Unable to determine the file format from the file name."
Jan
am 2 Okt. 2021
imwrite cannot write eps files. The EPS format is thought for vector graphics, which can be scaled freely. Therefore it is not suitable for saving a figure "as seen on the screen". A raster image like TIFF, PNG or GIF would be matching.
If you use print() to create an EPS of the screenshot taken by getframe, a JPEG image is embedded in the EPS (or maybe a TIFF?). This indirect approach is less usefull than storing a raster image directly.
Martim Zurita
am 21 Okt. 2021
Bearbeitet: Martim Zurita
am 21 Okt. 2021
Thanks for the explanation, Jan!
In the end I managed to save my figure as seen on screen as a .pdf, using the export_fig function and the code
export_fig test.pdf
John Petersen
am 25 Jan. 2013
1 Stimme
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 Kommentar
Image Analyst
am 25 Jan. 2013
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.
Kategorien
Mehr zu Printing and Saving finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!