{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import holoviews as hv\n", "import pandas as pd\n", "\n", "from holoviews import dim\n", "from bokeh.sampledata.gapminder import regions, life_expectancy\n", "\n", "hv.extension('bokeh')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Declaring data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "group1 = 'South Asia'\n", "group2 = 'East Asia & Pacific'\n", "\n", "group1_countries = list(regions[regions.Group==group1].index)\n", "group2_countries = list(regions[regions.Group==group2].index)\n", "\n", "group1_df = life_expectancy.loc[group1_countries]\n", "group1_df['Region'] = group1\n", "group2_df = life_expectancy.loc[group2_countries]\n", "group2_df['Region'] = group2\n", "\n", "data = pd.concat([group1_df, group2_df]).reset_index().melt('Region', life_expectancy.columns, var_name='Year', value_name='Life Expectancy')\n", "\n", "violin = hv.Violin(data, ['Year', 'Region'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "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)" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }