Data Visualization

altair

Describe what your chart should show, not how to draw it, and let the library do the rest.

Install it: pip install altair

What does it do?

Altair takes a different philosophy from most charting tools: instead of issuing step-by-step drawing instructions, you describe the relationships you want to see, this column on the x-axis, that column as color, this one as size, and Altair works out how to render the chart. This declarative approach is based on an established academic framework called Vega-Lite, essentially a well-tested grammar for describing any chart mathematically. The tradeoff is somewhat less fine-grained visual control than Matplotlib offers, but for common chart types the code you write is dramatically shorter and easier to reason about. It’s especially popular for quick, clean exploratory charts inside data science notebooks.

See it in action

This code describes a simple line chart by saying which numbers go on each axis, then saves the resulting picture as a web page.

import altair as alt
import pandas as pd

data = pd.DataFrame({"x": [1, 2, 3, 4], "y": [10, 20, 25, 30]})
chart = alt.Chart(data).mark_line().encode(x="x", y="y")
chart.save("chart.html")

Why would a non-developer care?

Describing what a chart should show, rather than manually coding every drawing step, means analysts spend less time fighting with plotting syntax and more time thinking about their data. This declarative approach, borrowed from data visualization research, lowers the mental overhead of exploring a new dataset.

Real-world examples

It’s popular in data science education and notebooks precisely because its concise syntax lets students focus on the underlying statistical relationships rather than plotting mechanics. Its underlying Vega-Lite specification is also used outside Python entirely, in web-based visualization tools, meaning the same visual grammar shows up across the broader data visualization ecosystem.

Who uses it

Data analysts and scientists who want fast, clean exploratory charts and prefer describing a visualization’s structure rather than coding its rendering.

How it compares to alternatives

Altair’s declarative approach contrasts with Matplotlib and Seaborn’s more imperative, step-by-step style, trading some flexibility for concise, readable code. It shares its underlying grammar, Vega-Lite, with other visualization tools built outside the Python ecosystem entirely.

Fun fact

Altair is named after the brightest star in the constellation Aquila, following a tradition in the Vega and Vega-Lite project family of naming related tools after stars.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries