Lab: Introduction to Altair

This week, we will continue to work with the Places-in-France dataset. This time, we will use Altair, a Python library for creating statistical visualizations.

The goals of this lab are:

  • Get a better understanding of grammar of statistical visualisations: spaces, mappings, marks, and encodings,
  • Give you a sense of a complementary, programmatic way of creating an interactive visualisation,
  • Understand the declarative way of thinking used by Altair, Vega-Lite, and D3.

With that in mind, let’s get started.

Installation

In this lab, we’ll use Jupyter Lab with Altair in Python. If you’re using a lab machine, you’ll need to install all of the necessary libraires first. The easiest way to do that is to run the command:

$ pip3 install -U jupyterlab altair vega vega_datasets

(If you’re on your personal machine, you might just run pip instead of pip3. Or use your preferred means of installing Python packages.)

That will take a few moments to run. While that’s happening, go ahead and create a folder for this assignment and download this assignment’s lab notebook into it.

Once everything has installed and the notebook has been downloaded and extracted, cd into the assignment directory and run jupyter lab:

$ jupyter lab

That should launch Jupyter Lab and open it in a new web browser. (If you see a blank page, make sure you’re using a modern browser such as Chrome/Chromium/Firefox/Safari.)


Creative Commons License Assignment based on one by Petra Isenberg, Jean-Daniel Fekete, Pierre Dragicevic and Frédéric Vernier under a Creative Commons Attribution-ShareAlike 3.0 License.