Measles Example#

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

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:

import numpy as np
import holoviews as hv
from holoviews import opts
import pandas as pd

Declaring data#

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)


overlay = (heatmap + agg * vline * marker).cols(1)
    opts.HeatMap(width=900, height=500, tools=['hover'], logz=True, 
                 invert_yaxis=True, labelled=[], toolbar='above',
                 xaxis=None, colorbar=True, clim=(1, np.nan)),
    opts.Overlay(width=900, height=200, show_title=False, xrotation=90))
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

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