Measles example

This notebook reproduces a visualization by the Wall Street Journal about the incidence of measles over time, which the brilliant Brian Granger adapted into an example for the Altair library.

Most examples work across multiple plotting backends, this example is also available for:

In [1]:
import numpy as np
import holoviews as hv
import pandas as pd
from holoviews import opts


Declaring data

In [2]:
url = ''
data = pd.read_csv(url, skiprows=2, na_values='-')

yearly_data = data.drop('WEEK', axis=1).groupby('YEAR').sum().reset_index()
measles = pd.melt(yearly_data, id_vars=['YEAR'], var_name='State', value_name='Incidence')

heatmap = hv.HeatMap(measles, label='Measles Incidence')
aggregate = hv.Dataset(heatmap).aggregate('YEAR', np.mean, np.std)

vline = hv.VLine(1963)
marker = hv.Text(1964, 800, 'Vaccine introduction', halign='left')

agg = hv.ErrorBars(aggregate) * hv.Curve(aggregate)


In [3]:
(heatmap + agg * vline * marker).opts(
    opts.HeatMap(aspect=1.4,invert_yaxis=True, show_values=False, show_frame=False,
                 labelled=[], xaxis=None, logz=True),
    opts.Layout(aspect_weight=1, fig_size=300, vspace=0, sublabel_format=None),
    opts.Overlay(aspect=3, show_title=False, bgcolor='white', 
                 show_legend=False, show_frame=False, xrotation=90),
    opts.VLine(color='black', ylim=(0, 1050))).cols(1)

Download this notebook from GitHub (right-click to download).