Skip to main content
Albero Academy

Showing & Saving

Display interactively or export to PNG, PDF and SVG at the right quality.

Foundations7 min

A finished figure is either shown on screen or saved to a file. Getting the export right — format, resolution, tight borders — is what makes a chart presentation- or publication-ready.

savefig

export to a file
fig.savefig("chart.png", dpi=300, bbox_inches="tight")
fig.savefig("chart.pdf") # vector — scales infinitely
fig.savefig("chart.svg") # vector — for the web

Choosing a format

FormatUse for
PNGRaster — slides, docs, the web (set dpi)
PDF/SVGVector — print, publication (scales cleanly)
JPGPhotos only — avoid for charts (lossy)

Key takeaways

  1. 01plt.show() displays interactively; fig.savefig() exports to a file.
  2. 02Use PNG (raster, set dpi) for slides/web; PDF/SVG (vector) for print/publication.
  3. 03dpi=300 and bbox_inches="tight" give crisp, well-cropped output.
  4. 04Save before show() — showing can clear the figure.

Finished this chapter?

Mark it complete to track your progress through Matplotlib.