import matplotlib.pyplot as plt
import pandas as pd
from mpl_ornaments.titles import set_title_and_subtitle

#1
fig, ax = plt.subplots(nrows=1, ncols=1)

#2
df = pd.read_csv('data/gdp-g7-2010-2020.csv', comment='#')

#3
df = df[df['Year'] == (year := 2020)]
df.sort_values(by='Total', inplace=True, ascending=False)

#4
ax.bar(x=df['Country'], height=df['Total'])

#5
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=25)

#6
fig.savefig('charts/bar-chart.png', dpi=300, bbox_inches='tight')