Life Expectancy Split Violin#

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


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#

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#

violin.opts(split='Region', xrotation=90, 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)
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).