import matplotlib.pyplot as plt
import pandas as pd
from mpl_ornaments.titles import set_title_and_subtitle

fig, ax = plt.subplots(nrows=1, ncols=1)

df = pd.read_csv('data/gdp-g7-2010-2020.csv', comment='#')

df = df[df['Year'] == (year := 2020)]
df.sort_values(by='Total', inplace=True, ascending=False)

#1
rects = ax.bar(x=df['Country'], height=df['Total'], linewidth=1, 
               edgecolor='black')

#2
ax.bar_label(container=rects, padding=3)

#3
ax.spines[['top', 'right', 'left']].set_visible(False)
#4
ax.get_yaxis().set_visible(False)

title = f'GDP of the G7 countries in {year}'
subtitle = 'In bn USD. Source: The World Bank.'
set_title_and_subtitle(fig=fig, title=title, subtitle=subtitle, 
                       alignment='left', h_offset=60)

fig.savefig('charts/bar-chart-with-style-variations.png', dpi=300,
            bbox_inches='tight')