Loading video player…

Plotting Declarative Charts With Altair (Overview)

There’s a moment many data analysts know well: you have a new dataset and a clear question, and you open a notebook only to find yourself writing boilerplate axis and figure setup before you’ve even looked at the data. Matplotlib gives you fine-grained control, but that control comes with a cost. Altair takes a completely different approach to data visualization in Python.

Instead of scripting every visual detail, you describe what your data means. This includes specifying which column goes on which axis, what should be colored, and what should be interactive. Altair then generates the visualization.

If you’re wondering whether it’s worth adding another visualization library to your toolkit, here’s how Altair and Matplotlib compare:

Use Case Pick Altair Pick Matplotlib
Interactive exploratory charts in notebooks ✅ —
Pixel-precise publication figures or 3D plots — ✅

Altair generates web-native charts. The output is HTML and JavaScript, which means charts render right in your notebook and can be saved as standalone HTML files or embedded in web pages. It’s not a replacement for Matplotlib, and it doesn’t try to be. Think of them as tools you reach for in different situations.

Download

Course Slides (.pdf)

7.9 MB
Download

Sample Code (.ipynb)

333.8 KB

00:00 Hello and welcome to this video course all about Plotting Declarative Charts With Altair. I’m David and I’m excited to show you what Altair can do. You might be coming here as a Matplotlib user who wants to create charts more quickly.

00:13 Maybe you want to write less boilerplate and would like to create charts in a much more rapid fashion. Or perhaps you’d just like to learn about how to create interactive charts out of the box with Python.

00:25 In any case, that’s what Altair is all about, writing quick interactive charts. By the end of this course, you’ll know how to tell the difference between declarative and imperative approaches to visualization—something you’ll learn about in the next lesson, in fact.

00:41 You’ll learn when Altair is the right choice or when to use a different visualization library like Matplotlib. You’ll learn to create different types of chart using the Altair library.

00:51 You’ll learn how to add interactivity to these charts. You’ll learn how to link your charts together so that interacting with one of the charts actually affects the other.

01:00 And finally, you’ll also learn how to export your final chart to HTML to make sharing much easier. So what is Altair? Altair is specifically a data visualization library in Python.

01:12 It creates charts in a method that we would call declarative. Its main use case is for natively interactive exploratory analysis, when you want to explore your data by quickly creating charts that are also interactive to help your exploration.

01:28 It’s not meant as a replacement for Matplotlib, but really it’s an alternative with different use cases. One thing to note is that the library is officially now called Vega-Altair to differentiate between a software company called Altair.

01:41 But when you import the library, and for the purposes of this course, we’re just going to refer to it as Altair. By the end of this course, you’re going to learn how to use Altair to create charts just like these.

01:53 These are two separate charts showing data about penguins. And if you interact with one of them, the other one also changes. And all this is done using Altair.

02:05 So let’s get started. In the next lesson, you’ll learn what it means for Altair to create charts declaratively.

Become a Member to join the conversation.