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
%output fig='svg'

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]:
hm_opts = dict(aspect=1.4, invert_yaxis=True, show_values=False, show_frame=False,
               xrotation=90, labelled=[], toolbar='above', xaxis=None)
overlay_opts = dict(aspect=3, show_title=False, bgcolor='white', show_legend=False, show_frame=False)
vline_opts = dict(color='black')
layout_opts = dict(aspect_weight=1, fig_size=300, vspace=0, sublabel_format=None)

opts = {'Layout': {'plot': layout_opts}, 'HeatMap': {'plot': hm_opts},
        'Overlay': {'plot': overlay_opts}, 'VLine': {'style': vline_opts}}

(heatmap + agg * vline * marker)(opts).cols(1)

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