Altair is a declarative statistical visualisation library for Python, based on Vega and Vega-Lite. In this blog-post, we're going to use it to visualise football data from last year's Premier League season.

Python offers a wealth of visualisation libraries, but Altair is special, because its entire architecture makes it easier to build fast, interactive visualisations.

Most Python visualisation libraries, such as matplotlib or bokeh, are imperative; this means that you define an object and change its state to encode the information you want. Altair is different, because you use a grammar to define links between data and features of your visualisation (for instance, an axis, the colour). Once you define these relationships, Altair and Vega figures out the rest and outputs a visualisation. These can be fully interactive and embedded on the front-end, or exported as an image.

In this example, we're going to be using Altair to plot some sample customer data:

To get the data in a shape where we can plot it, we're just going to resample it by day, so we can aggregate our observations. By default, Altair supports up to 5,000 rows – this may seem like a limitation, but their argument is that data should generally be processed and aggregated outside of the visualisation framework prior to plotting, like we will do here.

df.index = 
source = df.resample('D').mean().reset_index()