Azzera filtri
Azzera filtri

Save figure as seen on screen?

21 visualizzazioni (ultimi 30 giorni)
C
C il 25 Gen 2013
Modificato: Martim Zurita il 21 Ott 2021
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!

Risposte (2)

Jan
Jan il 25 Gen 2013
img = getframe(gcf);
imwrite(img.cdata, [FileName, '.png']);
  5 Commenti
Jan
Jan il 2 Ott 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
Martim Zurita il 21 Ott 2021
Modificato: Martim Zurita il 21 Ott 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

Accedi per commentare.


John Petersen
John Petersen il 25 Gen 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.

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by