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
fig.savefig("chart.png", dpi=300, bbox_inches="tight")fig.savefig("chart.pdf") # vector — scales infinitelyfig.savefig("chart.svg") # vector — for the web
Choosing a format
| Format | Use for |
|---|---|
| PNG | Raster — slides, docs, the web (set dpi) |
| PDF/SVG | Vector — print, publication (scales cleanly) |
| JPG | Photos only — avoid for charts (lossy) |
Key takeaways
- 01plt.show() displays interactively; fig.savefig() exports to a file.
- 02Use PNG (raster, set dpi) for slides/web; PDF/SVG (vector) for print/publication.
- 03dpi=300 and bbox_inches="tight" give crisp, well-cropped output.
- 04Save before show() — showing can clear the figure.
