How can I export figure as png?
Mostra commenti meno recenti
I have the script which creates 3D figure. The only way to save it is
hgsave(graph, [input, output, '\', string{i + 8}, '.png'],'-v7.3');
I tried different ways to save it as png and all failed. It stores only axis.
print(graph,'-dpng',[input,output,'\',string{i +8},'.png']);
saveas(graph, [input, output, '\', string{i + 8}], 'png');
hgexport(graph, [input, output, '\', string{i + 8}, '.png'], hgexport('factorystyle'), 'Format', 'png');
Risposta accettata
Più risposte (4)
Hi,
I create a figure and save it with the follwoing command:
saveas(gcf,'picture.png')
Perhaps
saveas(gcf, [input, output, '\', string{i + 8}], 'png');
works.
1 Commento
Tomas
il 7 Ott 2014
Starting in R2020a, you can use the exportgraphics function to export the contents of a figure as one of several file types, including a PNG file. This code plots a surface and exports the plot as a PNG file.
% Plot a surface
surf(peaks);
% Get the current figure
fig = gcf;
% Export the figure as a PNG
exportgraphics(fig,"mysurface.png")
exportgraphics supports both image and vector graphics file formats. If you export the figure as an image, MATLAB uses a resolution of 150 dpi. To export the figure so that it’s the same size and resolution as it appears in MATLAB, get the ScreenPixelsPerInch value from the graphics root object, and use that value to specify the resolution of the file.
sppi = get(groot,"ScreenPixelsPerInch");
exportgraphics(fig,"mysurface.png",Resolution=sppi)
exportgraphics has several options for configuring the output file. For example, you can choose from several file formats, create multi-page PDF files with embedded fonts as well as animated GIF files.
In R2025a, options were added to support SVG files, custom width and height values, and the ability to control the amount of padding (white space) around the graphic.
To compare exportgraphics to other methods of exporting figures, see Compare Ways to Export Graphics from Figures.
Michael Haderlein
il 7 Ott 2014
Modificato: Michael Haderlein
il 7 Ott 2014
0 voti
Did you try another renderer? I can't really explain a lot about it, but I think I once had a similar problem (though everything was black in my case) and choosing another renderer has fixed the case.
In case neither this nor the other suggestions work: I feel a bit embarrassed to mention it here, but once I was desperate enough to simply make a screenshot and save this. In case none of the solutions here works, this will for sure.
Categorie
Scopri di più su Printing and Saving in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
