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") df1 = df.drop('Total', axis=1) df2 = df.T.loc['Total'] fig, ax = plt.subplots(figsize=(10, 5)) ax.bar(df.index, df["0-19"] , width=1.7) ax.bar(df.index, df["20-64"], width=1.7, bottom=df["0-19"] ) ax.bar(df.index, df["65-74"] , width=1.7, bottom=df["0-19"] + df["20-64"] ) ax.bar(df.index, df["75+"] , width=1.7, bottom=df["0-19"] + df["20-64"]+ df["65-74"] ) ax2 = ax.twinx() ax2.plot(df2, label="Total", color="#5c1a86") ax.legend(df1.columns, fontsize=12, ncol=4, loc='upper right', frameon=True, facecolor="#dddddd") ax.set_ylim([0,150000]) ax2.set_ylim([0,150000]) plt.rcParams['font.family'] = 'sans-serif' plt.rcParams['font.sans-serif'] = ['Noto Sans Display'] plt.subplots_adjust(left=0.09, bottom=0.12, right=0.98, top=0.91) plt.title("Population Trends in Japan, by Age (IPSS Population statistics)", fontsize=15) plt.tick_params(labelsize=10, pad=4) ax.set_xlabel("Historic and Projected", size=10) ax.set_ylabel("1000 Population", 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(5)) ax.yaxis.set_major_locator(ticker.MultipleLocator(20000)) 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")