Altair Saving & Exporting
๐พ Basic save
chart.save("chart.html") # interactive, self-contained โ always works, no extra deps
chart.save("chart.json") # raw Vega-Lite spec
chart.save("chart.png") # static image โ needs extra setup, see below
chart.save("chart.svg") # static vector โ needs extra setup, see below
chart.save("chart.pdf") # needs extra setup, see belowPNG/SVG/PDF export requires an extra dependency (
vl-convert-pythonis the modern, recommended one). HTML and JSON work with zero extra setup.
pip install vl-convert-python๐ฏ Resolution for PNG export
chart.save("chart.png", ppi=300) # higher resolution for print quality๐ผ๏ธ Embedding in HTML manually
chart.save("chart.html", embed_options={"actions": False}) # hides the "..." export menu in the corner๐ In Jupyter
chart # just the last expression in a cell โ auto-renders interactivelyNo .show() or plt.show() equivalent needed inside Jupyter itself.
๐ Outside Jupyter (plain script)
chart.show() # opens in default browser via a local server๐ Getting the raw spec (for embedding elsewhere, e.g. a web app)
spec = chart.to_dict() # Python dict of the full Vega-Lite spec
spec_json = chart.to_json() # as a JSON string
to_dict()/to_json()is the bridge to using an Altair-built chart inside a JS frontend (Vega-Lite runtime), a Streamlit app, or any tool that accepts a raw Vega-Lite spec.
๐ฅ๏ธ Renderers (how charts get displayed)
alt.renderers.enable("default") # standard, works in Jupyter/JupyterLab
alt.renderers.enable("mimetype") # alternative for some notebook environments
print(alt.renderers.names()) # list available renderers๐งฎ Row limit warning
Altair embeds data directly in the chart spec and defaults to a 5,000-row limit, throwing a
MaxRowsErrorbeyond that. For larger data: aggregate before plotting, or disable the check.
alt.data_transformers.disable_max_rows() # removes the limit โ fine for moderate overages, risky for huge dataalt.data_transformers.enable("vegafusion") # better long-term fix: pushes aggregation to a backend, handles large data properly