text_html_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

df_medal = pd.read_csv('../input/beijing-2022-olympics/medals.csv')
df_total_medals = pd.read_csv('../input/beijing-2022-olympics/medals_total.csv')
df_events = pd.read_csv('../input/beijing-2022-olympics/events.csv')
df_athletes = pd.read_csv('../input/beijing-2022-olympics/athletes.csv')
s_athletes = pd.read_excel('../input/2021-olympics-in-tokyo/Athletes.xlsx')

columns = ['Order', 'Country', 'Bronze', 'Silver', 'Gold', 'Total', 'Order by Total', 'Country Code', 'Discipline']
df_total_medals = df_total_medals.reindex(columns=columns)

df_total_medals = df_total_medals.sort_index(ascending=False)
plt.rcParams['figure.dpi'] = 200
fig = plt.figure(figsize=(3, 30), facecolor='#f6f5f5')
gs = fig.add_gridspec(1, 1)
gs.update(wspace=1.5, hspace=0.05)
background_color = '#f6f5f5'
sns.set_palette(['#D8392B', '#CD7F32', '#C0C0C0', '#FFD700'])
ax0 = fig.add_subplot(gs[0, 0])
for s in ['right', 'top']:
    ax0.spines[s].set_visible(False)
ax0.set_facecolor(background_color)
ax0_sns = df_total_medals.plot(x='Country', y=['Discipline', 'Bronze', 'Silver', 'Gold'], kind='barh', ax=ax0, zorder=2, width=0.8)
ax0_sns.set_xlabel('Medals Count', fontsize=4, weight='bold')
ax0_sns.set_ylabel('Team Name', fontsize=4, weight='bold')
ax0_sns.grid(which='major', axis='x', zorder=0, color='#EEEEEE', linewidth=0.4)
ax0_sns.grid(which='major', axis='y', zorder=0, color='#EEEEEE', linewidth=0.4)
ax0_sns.tick_params(labelsize=3, width=0.5, length=1.5)
ax0_sns.legend(['Discipline', 'Bronze', 'Silver', 'Gold'], ncol=4, facecolor='#D8D8D8', edgecolor=background_color, fontsize=3, bbox_to_anchor=(1, 1.005), loc='upper right')
for p in ax0_sns.patches:
    value = f'{p.get_width():.0f}'
    x = p.get_x() + p.get_width() + 1
    y = p.get_y() + p.get_height() / 2
    ax0.text(x, y, value, ha='left', va='center', fontsize=3)
Xstart, Xend = ax0.get_xlim()
Ystart, Yend = ax0.get_ylim()
ax0_sns.text(Xend - 1, Yend + 0.3, f'Medals Table', fontsize=6, weight='bold', ha='right')
plt.show()