import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from mpl_ornaments.titles import set_title_and_subtitle


fig, ax = plt.subplots(nrows = 1, ncols = 1)

#1
df = pd.read_csv('data/life-expectancy-2021.csv', comment='#')

#2a
sns.boxplot(data=df, y='Life_expectancy', x='Continent', hue='Continent', 
            whis=1.5, showfliers=False, boxprops={'alpha':0.4}, ax=ax)
#2b
sns.stripplot(data=df, y='Life_expectancy', x='Continent', 
              hue='Continent', jitter=0.1, edgecolor='gray', linewidth=1, 
              ax=ax, alpha=0.5)

#3
ax.set(**{'xlabel': None, 'ylabel': None})

#4
ax.grid(visible=True, axis='y')
ax.spines[['top', 'right', 'left']].set_visible(False)

title = f'Life expectancy by continent (2021)'
subtitle = 'Both genders, in years. Source: The World Bank.'
set_title_and_subtitle(fig=fig, title=title, subtitle=subtitle, 
                       alignment='left', h_offset=40)

fig.savefig('charts/box-and-strip-plot.png', dpi=300, bbox_inches='tight')