Export charts to files

3.11.2

Select an output format and export at a size suitable for reports, slides, or the web.

On this page

Choose raster or vector

PNG is a raster format. figsize in inches and dpi determine pixel dimensions before cropping. SVG and PDF can preserve vector lines and text for scaling, although some elements can be rasterized.

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(6, 4), layout="constrained")
ax.bar(["Tea", "Cake"], [6, 4])
ax.set(ylabel="Units sold")
fig.savefig("sales.png", dpi=150, bbox_inches="tight")
fig.savefig("sales.svg", bbox_inches="tight")

Check the exported file

bbox_inches="tight" crops around figure content and can change final pixel dimensions. Open the saved file to check for clipped labels. For batch rendering, close each figure when finished.

Official references