Life expectancy split violin

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


In [1]:
import holoviews as hv
import pandas as pd

from holoviews import dim
from bokeh.sampledata.gapminder import regions, life_expectancy

hv.extension('bokeh')

Declaring data

In [2]:
group1 = 'South Asia'
group2 = 'East Asia & Pacific'

group1_countries = list(regions[regions.Group==group1].index)
group2_countries = list(regions[regions.Group==group2].index)

group1_df = life_expectancy.loc[group1_countries]
group1_df['Region'] = group1
group2_df = life_expectancy.loc[group2_countries]
group2_df['Region'] = group2

data = pd.concat([group1_df, group2_df]).reset_index().melt('Region', life_expectancy.columns, var_name='Year', value_name='Life Expectancy')

violin = hv.Violin(data, ['Year', 'Region'])

Plot

In [3]:
violin.opts(split='Region', responsive=True, min_height=500, show_legend=True, violin_width=1.5, legend_position='bottom_right', title='Life Expectancy by Year for Asian subregions', fontscale=1.5)
Out[3]:

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