Lab: Introduction to Altair

Today, we will work with a data set of Places-in-France using 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 programmatic way of creating an interactive visualisation that you can build into your data science workflows,
  • 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. First, make sure you have Jupyter Lab, Altair, and pre-requisites installed. If you use conda, run the command:

$ conda install -c condo-forge altair vega_datasets jupyterlab

If you use pip, then run:

$ pip install -U altair vega_datasets jupyterlab

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.