export_fig

A MATLAB toolbox for exporting publication quality figures
356.7K Downloads
Updated 5 Nov 2024

Editor's Note: Popular File 2011 2012 2013 2014 2015 2016 2017 2018

This file was selected as MATLAB Central Pick of the Week

This function saves a figure or single axes to one or more vector and/or bitmap file formats, and/or outputs a rasterized version to the workspace, with the following features:
  • Figure/axes reproduced as it appears on screen
  • Cropped/padded borders (optional)
  • Embedded fonts (vector formats)
  • Improved line and grid line styles
  • Anti-aliased graphics (bitmap formats)
  • Render images at native resolution (optional for bitmap formats)
  • Transparent background supported (pdf, eps, png, tiff, gif)
  • Semi-transparent patch objects supported (png, tiff)
  • RGB, CMYK or grayscale output (CMYK only with pdf, eps, tiff)
  • Variable image compression, including lossless (pdf, eps, jpg)
  • Optional rounded line-caps (pdf, eps)
  • Optionally append to file (pdf, tiff, gif)
  • Vector formats: pdf, eps, emf, svg
  • Bitmap formats: png, tiff, jpg, bmp, gif, clipboard, export to workspace
  • XKCD hand-drawn rendering style option
This function is especially suited to exporting figures for use in publications and presentations, because of the high quality and portability of media produced.
Basic syntax: export_fig(filename, [handle], options...)
Notes:
  • 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, and set the axes 'Color' property to 'none' where desired. Only some image formats support a transparent background, and only png/tiff support transparency of patch objects.
  • When exporting to vector format (pdf & eps), and to bitmap using the painters renderer, ghostscript (http://ghostscript.com) needs to be installed on your system
  • When exporting to eps, the pdftops program, a part of the Xpdf package, also needs to be installed. You can download this from http://xpdfreader.com
  • This submission was originally created by Oliver Woodford. Yair Altman maintains this utility since Jan 2015.
  • A single textual ad message is displayed once a week. I have no intention of removing the ad; if you don't want to see even a single ad once a week, don't use the program.
Report any problem or issue via GitHub: https://github.com/altmany/export_fig/issues - not here

Cite As

Yair Altman (2024). export_fig (https://github.com/altmany/export_fig/releases/tag/v3.47), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: MakeMovie, DT QP Project, Constitutive model of shape memory alloys, surface2tikz(fighandle,filename,varargin), Spectral stochastic finite element method: 1D Euler-Bernoulli beam example, expandaxes, Crack Monitor, LaTeX Output Classes for MatLab, fig2img, copyUIAxes, ExportPngInkscape(filename,dpi,handle), Mosaicator, Antarctic flight planning tools, WITio, Online portfolio selection with transaction costs including market impact costs, imageslices, PM Architectures Project, Semismooth* Newton method for contact friction problems, Simulation of von Kármán viscoelastic plates, Tight subplot with units in centimeter, efigure, matlab-save-figure, polarG(start_complex,end_complex,arrow_length,arrow_angle,colour_code,line_width), Microscopy Image Browser (MIB), ff, Microscopy Image Browser 2 (MIB2), alexludwigklein/MATLAB-Videos, Plot multiple surfaces multisurf(x,y,z,color), Matlab Icon for Linux (with Transparency), MAGIC - MATLAB Generic Imaging Component, append_pdfs, Google Earth Overlay, Multiple Colormaps, EPS Utility Toolbox, Export figure to 3D interactive PDF, Co-Blade: Software for Analysis and Design of Composite Blades, Color Checker Chart, Save figure to file, choose the dimensions and crop figure, jrichter24/toPPT, Simulation of Random Walk, Multiple Page PDF, JCDstatusPlot, XivelyRead, imsavecircles, PlotPub - Publication Quality Graphs in MATLAB, Laser, Filters and CMOS-Imager Calibration, Philips Hue Lamp Controller, HCPARULA: High Contrast Parula-like Colormap Generator, bibget, Export Figure Widget (efw), export_tex, Causal State Modeller Toolbox, Machine learning - balancing a stack of balls, Fast and efficient spectral clustering, latexfigure, FIGUREMAKER - Publication quality figures with matlab, TeloTool - Terminal Restriction Fragment Analysis, Evaluation of intrinsic rotations

Community Treasure Hunt

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

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes
3.47

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.47

3.46

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.46

3.45

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.45

3.44

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.44

3.43.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.43

3.42.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.42

3.41.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.41

3.40.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.40

3.39.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.39

3.38.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.38

3.37.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.37

3.36.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.36

3.35.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.35

3.34.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.34

3.33.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.33

3.32.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.32

3.31.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.31

3.30.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.30

3.29.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.29

3.28

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.28

3.27

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.27

3.26

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.26

3.25

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.25

3.24

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.24

3.23

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.23

3.22

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.22

3.21

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.21

3.20

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.20

3.19

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.19

3.18

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.18

3.17

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.17

3.16

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.16

3.15

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.15

3.14

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.14

3.13

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.13

3.12

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.12

3.11

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.11

3.10

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.10

3.09

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.09

3.07

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.07

3.06

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.06

3.05

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.05

3.04

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.04

3.3.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.03

3.1.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.01

3.0.0.0

See release notes for this release on GitHub: https://github.com/altmany/export_fig/releases/tag/v3.0

2.0.0.0

new version

1.99.0.0

Added -update option to download and install the latest version of export_fig

1.98.0.0

Added the -clipboard input arg for optional clipboard output (credit: Jiro Doke's imclipboard function)

1.97.0.0

Added link to technical description webpage

1.92.0.0

Several fixes; more informative error messages; improved functionality

1.91.0.0

Passed maintenance responsibility over to Yair Altman

1.90.0.0

Support for R2014b (actually added some time ago, but the FEX update date didn't reflect this)

1.89.0.0

Update description

1.88.0.0

Added support for HG2

1.87.0.0

Replace acknowledgements

1.86.0.0

Switch to GitHub repository

1.85.0.0

Fix bug in isolate axes; thanks to Remington Reid for bringing the issue to my attention.

1.84.0.0

Allow setting of resolution for vector formats (thanks to Jan Jaap Meijer for suggesting this). Fix bug in isolate_axes (thanks to Will Grant for this).

1.83.0.0

Fixed a font swapping bug and a MATLAB bug affecting the export of white lines to EPS. Thanks to George and Sebastian for reporting the issues.

1.81.0.0

Fixed a font swapping bug and a MATLAB bug affecting the export of white lines to EPS. Thanks to George and Sebastian for reporting the issues.

1.80.0.0

Fixed bug with calling ghoscript 9.07 in Linux. Many thanks to Jannik for the fix.

1.79.0.0

Access user strings in text, not binary mode, to avoid errors. Now swap fonts in axes labels when exporting in vector format. Thanks to Christian and Rasmus Ischebeck for pointing out these respective errors.

1.78.0.0

Allow export of uipanel objects, and improve finding Ghostscript on Windows. Thanks to michael and Ratish Punnoose for highlighting these issues.

1.77.0.0

Bug fix to font swapping in vector formats, fixed paper orientation bug and removed conflict with the path function. Many thanks to Malcolm Hudson, Michael Watts and Michel Slivitzky for reporting those issues respectively.

1.45.0.0

Fix to bug introduced by R2012b

1.44.0.0

Add ability to add bookmarks based on figure names into PDFs - thanks to Petr Nechaev for this. Keep tick marks fixed - thanks to Arcelia Arrieta for this.

1.43.0.0

Make font swapping case insensitive. Fix bug affecting export to bitmap using painters in r2012a (thanks to Andy Matthews for reporting it).

1.42.0.0

Fixed a bug to do with copyfig not being available to export_fig. Thanks to Bob Fratantonio for pointing it out.

1.41.0.0

A bug fix to the previous change, ensuring that axes limits are correctly set. Thanks to Tobias Lamour for reporting the issue.

1.40.0.0

Ensure axes limits are the same on screen and printed.

1.39.0.0

Fix bug when exporting tall figures to bitmap using the painters renderer. Thanks to Ken Campbell for reporting it.

1.38.0.0

Improve font swapping behaviour. Thanks to Anna Rafferty and Adam Jackson for reporting issues.

1.37.0.0

Fix bug affecting export using -painters with spaces in font names. Thanks to David Szwer for reporting the issue.

1.36.0.0

More reliable export of non-standard fonts using painters renderer.

1.35.0.0

Allow use of arbitrary fonts with the painters renderer, e.g. in eps and pdf files.

1.34.0.0

Various bug fixes - thanks to Phil Trinh, Mathieu Morlighem and Meelis Lootus for reporting the issues. Also added new -transparent option, and set default anti-aliasing down to -a3.

1.33.0.0

Fix to bug in print2array causing an error when exporting using painters with a white background. Thanks to Tobiar Lamour for reporting it.

1.32.0.0

Fix bitmap cropping with painters renderer. Make bitmap outputs exactly the right size. Suppress warnings by setting EraseModes to normal when using opengl or zbuffer renderers (thanks to Pawel Kocieniewski for reporting the issue).

1.31.0.0

Bug fix to ghostscript.m mostly affecting Linux (thanks to Paul Durack for reporting it).

1.30.0.0

Find 64-bit Ghostscript on Windows (thanks to Paul Durack and Shaun Kline for both reporting this issue). Fix bug in isolate_axes (thanks to Rosella Blatt for reproting this).

1.28.0.0

Save user specific paths in a single, hidden directory. Put isolate_axes code in a separate function.

1.27.0.0

Enable exporting of multiple axes (when a subset of all axes). Don't save user specific paths in .m files that may be version controlled (thanks to Jonas Dorn for the suggestion). Minor bug fixes.

1.26.0.0

Faster bitmap export using hardcopy. Better error checking for when exporting to non-existent directories (thanks to Aldebaro Klautau for reporting this).

1.25.0.0

Isolate axes better in presence of gui objects (thanks to Tammy Threadgill for reporting the issue). Maintain resolution of very small images in vector formats when using lossless compression (thanks to Scott for reporting the issue).

1.24.0.0

Added ability to append to tiff. Added link to usage examples web page (thanks to Brett Shoelson for the suggestion).

1.23.0.0

Fixed bug which caused bitmaps to be poorly rendered when using the painters renderer on figures with many patches in. Also added fix to bug reported by Andrew Matthews (thanks!) affecting export in -nodisplay mode.

1.22.0.0

Fix to bug which caused an error when exporting to transparent bitmap with no colorbar present (introduced 8th April 2010). Thanks to Gracee for reporting it.

1.21.0.0

Fix for R2006b (possibly even R2007a) and earlier: move embedded fonts after bounding box information. Thanks to Sylvain Fa for reporting the problem.

1.20.0.0

Fix to colorbar axes color bug with transparent bitmap export (thanks to Roland Martin for reporting it). Look for ghostcript in default location on 64 bit Windows (thanks to suggestion by Nathan Childress).

1.19.0.0

Added ability to vary quality/compression level for jpg, pdf & eps output. Thank you to Fabio Viola for pointing out compression artifacts using the default settings.

1.18.0.0

Improved accuracy of native resolution feature in some circumstances.

1.17.0.0

Added -native option for exporting to bitmap at native resolution of an image. Fixed uigetdir title problem on MAC OS X (thanks to Jonas for the bug report).

1.16.0.0

Improved rendering of dashed and dotted lines for bitmap outputs using the -painters algorithm. This overcomes the "shrinking dash" problem mentioned by Yvonne Haesevoets (thanks!).

1.15.0.0

No change to the file, just a correction - I thank Paul Soderlind for suggesting the grayscale output option, not Bob Sica (apologies to you both).

1.14.0.0

Bug fix (thanks, Andreas Offenhaeuser). Added grayscale option (suggestion thanks to Bob Sica). Added correct resolution for tiff & png (sugestion thanks to Yvonne Haesevoets).

1.13.0.0

Fixed bug that meant -tif lead to jpeg being output instead.

1.12.0.0

Appending to end of pdf files is now off by default, and enabled by the -append option. Suggested by Clark Richards.

1.11.0.0

Added ability to export at any resolution (bitmap outputs only) and also in CMYK colorspace (tiff, pdf, eps only).

1.10.0.0

Added option to use zbuffer renderer for bitmaps. This avoids some errors caused by bugs in the opengl renderer.
Fixed bug when exporting greyscale figures with an alphamatte (thanks to Annette for pointing it out).

1.9.0.0

Added options to disable cropping and set level of anti-aliasing. Added a fix to get round a rendering bug in print (thanks to Johannes Korsawe for pointing it out).

1.8.0.0

Export colorbars associated with subplots when in a uipanel. Thanks to Johannes Korsawe for pointing out the bug.

1.7.0.0

Fixed bug to allow exporting of axes that are children of uipanels. Thanks to Stefan for pointing out the bug.

1.6.0.0

Added ability to compute transparency of patch objects when outputting to png and exporting to workspace.

1.3.0.0

Incorporated Christian Dorion's patch for updating ghostscript (and also pdftops) path. Fixed bug that didn't correctly detect if pdftops path was valid (due to a MATLAB/Windows bug).

1.2.0.0

Added ability to append to pdf files, as suggested by Matt C. Corrected some help text.

1.1.0.0

Added ability to export rasterized figure straight to the workspace.

1.0.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.