import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.ticker as ticker
df = pd.read_csv("data.tsv", index_col=0 , sep = "\t")
df = df.fillna(0).div(1000, fill_value=0).fillna(0)
df1 = df.drop('Total of Social Benefit', axis=1).T
df2 = df.reindex(columns=['Total of Social Benefit'])
fig, ax = plt.subplots(figsize=(10, 5))
ax2 = ax.twinx()
ax.plot(df2, label="Total of Social Benefit", color="#5E95CD")
ax.fill_between( df2.index ,0, df2['Total of Social Benefit'].values, color="lightblue", alpha=0.5)
for i in range( len(df1) ):
ax2.bar(df1.columns, df1.iloc[i] , width=1, bottom=df1.iloc[:i].sum(), label=df1.index[i])
lines, labels = ax.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax2.legend(lines + lines2, labels + labels2, facecolor="#eeeeee" ,ncol=2, fontsize=12,loc='upper left')
ax.set_ylim([0,1400])
ax2.set_ylim([0,1400])
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = ['Noto Sans Display']
plt.subplots_adjust(left=0.07, bottom=0.07, right=0.98, top=0.91)
plt.title("Social benefits for elderly in Japan (IPSS,2022)", fontsize=20)
plt.tick_params(labelsize=10, pad=4)
ax.set_ylabel("hundred billion JPY", size=12)
plt.setp(ax.get_xticklabels(), fontsize=8, rotation=75)
plt.setp(ax.get_yticklabels(), fontsize=9 )
ax.xaxis.set_major_locator(ticker.MultipleLocator(2))
ax.yaxis.set_major_locator(ticker.MultipleLocator(250))
ax2.set_yticklabels([])
ax2.set_yticks([])
ax.minorticks_on()
ax.set_axisbelow(True)
ax2.set_axisbelow(True)
ax.grid(True, which='major',color='#cccccc',linestyle='-', axis="y")
ax.grid(True, which='minor',color='#eeeeee',linestyle='--', axis="y")
ax2.grid(None,which='major')
plt.savefig("image.svg")