ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation. |
Go to the source code of this file.
Functions | |
function | savefig (in varargin) |
Export figures in a publication-quality format. More... | |
function savefig | ( | in | varargin | ) |
Export figures in a publication-quality format.
This function saves a figure or single axes to one or more vectors and/or bitmap file formats and/or outputs a rasterized version to the workspace, with the following properties:
This function is especially suited to exporting figures for use in publications and presentations because of the high quality and portability of media produced.
Note that the background color and figure dimensions are reproduced (the latter approximately, and ignoring cropping & magnification) in the output file.
For transparent background (and semi-transparent patch objects), use the -transparent
option or set the figure 'Color'
property to 'none'
.
To make axes transparent set the axes 'Color'
property to 'none'
.
PDF, EPS, TIF, and PNG are the only formats that support a transparent background.
Only TIF and PNG formats support the transparency of patch objects.
The choice of renderer (opengl/zbuffer/painters) greatly impacts the output quality.
The default value (opengl for bitmaps, painters for vector formats) generally gives good results, but if you are not satisfied, then try another renderer.
When exporting to vector format (PDF & EPS) and bitmap format using the painters renderer, this function requires that ghostscript is installed on your system.
You can download this from: http://www.ghostscript.com
When exporting to EPS, pdftops from the Xpdf function suite are also required.
You can download this from: http://xpdfreader.com
SVG output uses MATLAB's built-in SVG export if available, or otherwise the fig2svg (https://github.com/kupiqu/fig2svg) or plot2svg (https://github.com/jschwizer99/plot2svg) utilities, if available.
[in] | varargin | : Any property, value pair of the following set:
|
imageData
: The output image cube of type uint8
of shape [M, N, C]
containing the exported figure data.alpha
: The output image matrix of shape [M, N]
of alpha-matte values in the range [0, 1]
for the case of transparent background.
Possible calling interfaces ⛓
Example usage ⛓
Final Remarks ⛓
If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.
This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.
Copyright (C) Oliver Woodford 2008-2014, Yair Altman 2015-
/// The idea of using ghostscript is inspired by Peder Axensten's SAVEFIG /// (fex id: 10889) which is itself inspired by EPS2PDF (fex id: 5782). /// The idea for using pdftops came from the MATLAB newsgroup (id: 168171). /// The idea of editing the EPS file to change line styles comes from Jiro /// Doke's FIXPSLINESTYLE (fex id: 17928). /// The idea of changing dash length with line width came from comments on /// fex id: 5743, but the implementation is mine :) /// The idea of anti-aliasing bitmaps came from Anders Brun's MYAA (fex id: 20979). /// The idea of appending figures in pdfs came from Matt C in comments on the /// FEX (id: 23629) /// Thanks to Roland Martin for pointing out the colour MATLAB /// bug/feature with colorbar axes and transparent backgrounds. /// Thanks also to Andrew Matthews for describing a bug to do with the figure /// size changing in -nodisplay mode. I couldn't reproduce it, but included a /// fix anyway. /// Thanks to Tammy Threadgill for reporting a bug where an axes is not /// isolated from gui objects. /// /// 23/02/12: Ensure that axes limits don't change during printing /// 14/03/12: Fix bug in fixing the axes limits (thanks to Tobias Lamour for reporting it). /// 02/05/12: Incorporate patch of Petr Nechaev (many thanks), enabling bookmarking of figures in pdf files. /// 09/05/12: Incorporate patch of Arcelia Arrieta (many thanks), to keep tick marks fixed. /// 12/12/12: Add support for isolating uipanels. Thanks to michael for suggesting it. /// 25/09/13: Add support for changing resolution in vector formats. Thanks to Jan Jaap Meijer for suggesting it. /// 07/05/14: Add support for '~' at start of path. Thanks to Sally Warner for suggesting it. /// 24/02/15: Fix MATLAB R2014b bug (issue #34): plot markers are not displayed when ZLimMode='manual' /// 25/02/15: Fix issue #4 (using HG2 on R2014a and earlier) /// 25/02/15: Fix issue #21 (bold TeX axes labels/titles in R2014b) /// 26/02/15: If temp dir is not writable, use the user-specified folder for temporary EPS/PDF files (Javier Paredes) /// 27/02/15: Modified repository URL from github.com/ojwoodford to /altmany; Indented main function; Added top-level try-catch block to display useful workarounds /// 28/02/15: Enable users to specify optional ghostscript options (issue #36) /// 06/03/15: Improved image padding & cropping thanks to Oscar Hartogensis /// 26/03/15: Fixed issue #49 (bug with transparent grayscale images); fixed out-of-memory issue /// 26/03/15: Fixed issue #42: non-normalized annotations on HG1 /// 26/03/15: Fixed issue #46: Ghostscript crash if figure units <> pixels /// 27/03/15: Fixed issue #39: bad export of transparent annotations/patches /// 28/03/15: Fixed issue #50: error on some MATLAB versions with the fix for issue #42 /// 29/03/15: Fixed issue #33: bugs in MATLAB's print() function with -cmyk /// 29/03/15: Improved processing of input args (accept space between param name & value, related to issue #51) /// 30/03/15: When exporting *.fig files, then saveas *.fig if figure is open, otherwise export the specified fig file /// 30/03/15: Fixed edge case bug introduced yesterday (commit #ae1755bd2e11dc4e99b95a7681f6e211b3fa9358) /// 09/04/15: Consolidated header comment sections; initialize output vars only if requested (nargout>0) /// 14/04/15: Workaround for issue #45: lines in image subplots are exported in invalid color /// 15/04/15: Fixed edge-case in parsing input parameters; fixed help section to show the -depsc option (issue #45) /// 21/04/15: Bug fix: Ghostscript croaks on % chars in output PDF file (reported by Sven on FEX page, 15-Jul-2014) /// 22/04/15: Bug fix: Pdftops croaks on relative paths (reported by Tintin Milou on FEX page, 19-Jan-2015) /// 04/05/15: Merged fix #63 (Kevin Mattheus Moerman): prevent tick-label changes during export /// 07/05/15: Partial fix for issue #65: PDF export used painters rather than opengl renderer (thanks Nguyenr) /// 08/05/15: Fixed issue #65: bad PDF append since commit #e9f3cdf 21/04/15 (thanks Robert Nguyen) /// 12/05/15: Fixed issue #67: exponent labels cropped in export, since fix #63 (04/05/15) /// 28/05/15: Fixed issue #69: set non-bold label font only if the string contains symbols (\beta etc.), followup to issue #21 /// 29/05/15: Added informative error message in case user requested SVG output (issue #72) /// 09/06/15: Fixed issue #58: -transparent removed anti-aliasing when exporting to PNG /// 19/06/15: Added -update option to download and install the latest version of savefig /// 07/07/15: Added -nofontswap option to avoid font-swapping in EPS/PDF /// 16/07/15: Fixed problem with anti-aliasing on old MATLAB releases /// 11/09/15: Fixed issue #103: magnification must never become negative; also fixed reported error msg in parsing input params /// 26/09/15: Alert if trying to export transparent patches/areas to non-PNG outputs (issue #108) /// 04/10/15: Do not suggest workarounds for certain errors that have already been handled previously /// 01/11/15: Fixed issue #112: use same renderer in print2eps as savefig (thanks to Jesús Pestana Puerta) /// 10/11/15: Custom GS installation webpage for MacOS. Thanks to Andy Hueni via FEX /// 19/11/15: Fixed clipboard export in R2015b (thanks to Dan K via FEX) /// 21/02/16: Added -c option for indicating specific crop amounts (idea by Cedric Noordam on FEX) /// 08/05/16: Added message about possible error reason when groot.Units~=pixels (issue #149) /// 17/05/16: Fixed case of image YData containing more than 2 elements (issue #151) /// 08/08/16: Enabled exporting transparency to TIF, in addition to PNG/PDF (issue #168) /// 11/12/16: Added alert in case of error creating output PDF/EPS file (issue #179) /// 13/12/16: Minor fix to the commit for issue #179 from 2 days ago /// 22/03/17: Fixed issue #187: only set manual ticks when no exponent is present /// 09/04/17: Added -linecaps option (idea by Baron Finer, issue #192) /// 15/09/17: Fixed issue #205: incorrect tick-labels when Ticks number don't match the TickLabels number /// 15/09/17: Fixed issue #210: initialize alpha map to ones instead of zeros when -transparent is not used /// 18/09/17: Added -font_space option to replace font-name spaces in EPS/PDF (workaround for issue #194) /// 18/09/17: Added -noinvert option to solve some export problems with some graphic cards (workaround for issue #197) /// 08/11/17: Fixed issue #220: axes exponent is removed in HG1 when TickMode is 'manual' (internal MATLAB bug) /// 08/11/17: Fixed issue #221: alert if the requested folder does not exist /// 19/11/17: Workaround for issue #207: alert when trying to use transparent bgcolor with -opengl /// 29/11/17: Workaround for issue #206: warn if exporting PDF/EPS for a figure that contains an image /// 11/12/17: Fixed issue #230: use OpenGL renderer when exported image contains transparency (also see issue #206) /// 30/01/18: Updated SVG message to point to https://github.com/kupiqu/plot2svg and display user-selected filename if available /// 27/02/18: Fixed issue #236: axes exponent cropped from output if on right-hand axes /// 29/05/18: Fixed issue #245: process "string" inputs just like 'char' inputs /// 13/08/18: Fixed issue #249: correct black axes color to off-black to avoid extra cropping with -transparent /// 27/08/18: Added a possible file-open reason in EPS/PDF write-error message (suggested by "craq" on FEX page) /// 22/09/18: Xpdf website changed to xpdfreader.com /// 23/09/18: Fixed issue #243: only set non-bold font (workaround for issue #69) in R2015b or earlier; warn if changing font /// 23/09/18: Workaround for issue #241: don't use -r864 in EPS/PDF outputs when -native is requested (solves black lines problem) /// 18/11/18: Issue #261: Added informative alert when trying to export a uifigure (which is not currently supported) /// 13/12/18: Issue #261: Fixed last commit for cases of specifying axes/panel handle as input, rather than a figure handle /// 13/01/19: Issue #72: Added basic SVG output support /// 04/02/19: Workaround for issues #207 and #267: -transparent implies -noinvert /// 08/03/19: Issue #269: Added ability to specify format-specific options for PNG,TIF,JPG outputs; fixed help section /// 21/03/19: Fixed the workaround for issues #207 and #267 from 4/2/19 (-transparent now does *NOT* imply -noinvert; -transparent output should now be ok in all formats) /// 12/06/19: Issue #277: Enabled preservation of figure's PaperSize in output PDF/EPS file /// 06/08/19: Remove warning message about obsolete JavaFrame in R2019b /// 30/10/19: Fixed issue #261: added support for exporting uifigures and uiaxes (thanks to idea by @MarvinILA) /// 12/12/19: Added warning in case user requested anti-aliased output on an aliased HG2 figure (issue #292) /// 15/12/19: Added promo message /// 08/01/20: (3.00) Added check for newer version online (initialized to version 3.00) /// 15/01/20: (3.01) Clarified/fixed error messages; Added error IDs; easier -update; various other small fixes /// 20/01/20: (3.02) Attempted fix for issue #285 (unsupported patch transparency in some Ghostscript versions); Improved suggested fixes message upon error /// 03/03/20: (3.03) Suggest to upload problematic EPS file in case of a Ghostscript error in eps2pdf (& don't delete this file) /// 22/03/20: (3.04) Workaround for issue #15; Alert if ghostscript file not found on MATLAB path /// 10/05/20: (3.05) Fix the generated SVG file, based on Cris Luengo's SVG_FIX_VIEWBOX; Don't generate PNG when only SVG is requested /// 02/07/20: (3.06) Significantly improved performance (speed) and fidelity of bitmap images; Return alpha matrix for bitmap images; Fixed issue #302 (-update bug); Added EMF output; Added -clipboard formats (image,bitmap,emf,pdf); Added hints for exportgraphics/copygraphics usage in certain use-cases; Added description of new version features in the update message; Fixed issue #306 (yyaxis cropping); Fixed EPS/PDF auto-cropping with -transparent /// 06/07/20: (3.07) Fixed issue #307 (bug in padding of bitmap images); Fixed axes transparency in -clipboard:emf with -transparent /// 07/07/20: (3.08) Fixed issue #308 (bug in R2019a and earlier) /// 18/07/20: (3.09) Fixed issue #310 (bug with tiny image on HG1); Fixed title cropping bug /// 23/07/20: (3.10) Fixed issues #313,314 (figure position changes if units ~= pixels); Display multiple versions change-log, if relevant; Fixed issue #312 (PNG: only use alpha channel if -transparent was requested) /// 30/07/20: (3.11) Fixed issue #317 (bug when exporting figure with non-pixels units); Potential solve also of issue #303 (size change upon export) /// 14/08/20: (3.12) Fixed some exportgraphics/copygraphics compatibility messages; Added -silent option to suppress non-critical messages; Reduced promo message display rate to once a week; Added progress messages during savefig('-update') /// 07/10/20: (3.13) Added version info and change-log links to update message (issue #322); Added -version option to return the current savefig version; Avoid JavaFrame warning message; Improved exportgraphics/copygraphics infomercial message inc. support of upcoming MATLAB R2021a /// 10/12/20: (3.14) Enabled user-specified regexp replacements in generated EPS/PDF files (issue #324) /// 01/07/21: (3.15) Added informative message in case of setopacityalpha error (issue #285) /// 26/08/21: (3.16) Fixed problem of white elements appearing transparent (issue #330); clarified some error messages /// 27/09/21: (3.17) Made MATLAB's builtin export the default for SVG, rather than fig2svg/plot2svg (issue #316); updated transparency error message (issues #285, #343); reduced promo message frequency /// 03/10/21: (3.18) Fixed warning about invalid escaped character when the output folder does not exist (issue #345) /// 25/10/21: (3.19) Fixed print error when exporting a specific subplot (issue #347); avoid duplicate error messages /// 11/12/21: (3.20) Added GIF support, including animated & transparent-background; accept format options as cell-array, not just nested struct /// 20/12/21: (3.21) Speedups; fixed exporting non-current figure (hopefully fixes issue #318); fixed warning when appending to animated GIF /// 02/03/22: (3.22) Fixed small potential memory leak during screen-capture; expanded exportgraphics message for vector exports; fixed rotated tick labels on R2021a+ /// 02/03/22: (3.23) Added -toolbar and -menubar options to add figure toolbar/menubar items for interactive figure export (issue #73); fixed edge-case bug with GIF export /// 14/03/22: (3.24) Added support for specifying figure name in addition to handle; added warning when trying to export TIF/JPG/BMP with transparency; use current figure as default handle even when its HandleVisibility is not 'on' /// 16/03/22: (3.25) Fixed occasional empty files due to excessive cropping (issues #318, #350, #351) /// 01/05/22: (3.26) Added -transparency option for TIFF files /// 15/05/22: (3.27) Fixed EPS bounding box (issue #356) /// 04/12/22: (3.28) Added -metadata option to add custom info to PDF files; fixed -clipboard export (transparent and gray-scale images; deployed apps; old Matlabs) /// 03/01/23: (3.29) Use silent mode by default in deployed apps; suggest installing ghostscript/pdftops if required yet missing; fixed invalid chars in export filename; reuse existing figure toolbar if available /// 03/02/23: (3.30) Added -contextmenu option to add interactive context-menu items; fixed: -menubar,-toolbar created the full default figure menubar/toolbar if not shown; enlarged toolbar icon; support adding savefig icon to custom toolbars; alert if specifying multiple or invalid handle(s) /// 20/02/23: (3.31) Fixed PDF quality issues as suggested by @scholnik (issues #285, #368); minor fixes for MacOS/Linux; use figure's FileName property (if available) as the default export filename; added -gif optional format parameter; Display the export folder (full pathname) in menu items when using -toolbar, -menubar and/or -contextmenu /// 21/02/23: (3.32) Fixed EPS export error handling in deployed apps; use MATLAB's builtin EPS export if pdftops is not installed or fails; disabled EMF export option on MacOS/Linux; fixed some EMF warning messages; don't export PNG if only -toolbar etc were specified /// 23/02/23: (3.33) Fixed PDF -append (issue #369); Added -notify option to notify user when the export is done; propagate all specified savefig options to -toolbar,-menubar,-contextmenu exports; -silent is no longer set by default in deployed apps (i.e. you need to call -silent explicitly) /// 23/03/23: (3.34) Fixed error when exporting axes handle to clipboard without filename (issue #372) /// 11/04/23: (3.35) Added -n,-x,-s options to set min, max, and fixed output image size (issue #315) /// 13/04/23: (3.36) Reduced (hopefully fixed) unintended EPS/PDF image cropping (issues #97, #318); clarified warning in case of PDF/EPS export of transparent patches (issues #94, #106, #108) /// 23/04/23: (3.37) Fixed run-time error with old MATLAB releases (issue #374); -notify console message about exported image now displays black (STDOUT) not red (STDERR) /// 15/05/23: (3.38) Fixed endless recursion when using savefig in Live Scripts (issue #375); don't warn about exportgraphics/copygraphics alternatives in deployed mode /// 30/05/23: (3.39) Fixed exported bgcolor of uifigures or figures in Live Scripts (issue #377) /// 06/07/23: (3.40) For Tiff compression, use AdobeDeflate codec (if available) instead of Deflate (issue #379) /// 29/11/23: (3.41) Fixed error when no filename is specified nor available in the exported figure (issue #381) /// 05/12/23: (3.42) Fixed unintended cropping of colorbar title in PDF export with -transparent (issues #382, #383) /// 07/12/23: (3.43) Fixed unintended modification of colorbar in bitmap export (issue #385) ///