import matplotlib as mp import matplotlib.pyplot as plt from cycler import cycler import pandas as pd import matplotlib.ticker as ticker df = pd.read_csv("data.tsv", index_col=0 , sep = "\t") fig, ax = plt.subplots(figsize=(10, 6)) ax2 = ax.twinx() plt.rcParams['font.family'] = 'sans-serif' plt.rcParams['font.sans-serif'] = ['Noto Sans'] plt.subplots_adjust(left=0.10, bottom=0.21, right=0.99, top=0.90) ax.bar(df.index, df['Tax']* -1, color="#9467bd", label="Tax") ax.bar(df.index, df['Social Insurance'] *-1 , color="#e377c2", bottom=df['Tax']*-1, label="Social Insurance") ax.bar(df.index, df['Cash Benefits'], color="#2ca02c", label="Cash Benefits") ax.bar(df.index, df['Service Benefits'], color="#98DF8A", label="Service Benefits", bottom=df['Cash Benefits'] ) ax.axhspan(-300,0, color="lightblue", alpha=0.3 , zorder=-20) ax.set_ylim([-300,1000]) ax.set_axisbelow(True) ax.set_xlabel("Income class (10,000 JPY)", fontsize=12) ax.set_ylabel("Income,Tax and Transfers (10,000 JPY)", fontsize=14) ax.margins(0.05) ax.add_line(mp.lines.Line2D([0.584, 0.584], [0, 1], ls=":", c="red", alpha=0.3, transform=ax.transAxes)) ax2.set_prop_cycle( plt.rcParams['axes.prop_cycle'] ) ax2.plot(df["Raw Income"], lw=3, label="Raw Income", ls="--") ax2.plot(df["Redistributed Income"], lw=3, label="Redistributed Income") ax2.set_ylim([-300,1000]) ax2.set_yticklabels([]) ax2.set_yticks([]) ax2.margins(0.05) lines, labels = ax.get_legend_handles_labels() lines2, labels2 = ax2.get_legend_handles_labels() fig.legend(lines + lines2, labels + labels2, facecolor="#eeeeee" , ncol=6, fontsize=9,loc='lower center') plt.title("Income redistribution in Japan by income class\n(MHLW Income redistribution survey, 2023)", fontsize=15) plt.tick_params(labelsize=9, pad=4) plt.setp(ax.get_xticklabels(), fontsize=9, rotation=60) plt.setp(ax.get_yticklabels(), fontsize=10 ) ax.minorticks_on() ax.yaxis.set_major_locator(ticker.MultipleLocator(100)) ax.yaxis.set_minor_locator(ticker.MultipleLocator(50)) ax.grid(True, which='major',color='#eeeeee',linestyle='--', axis="x") ax.grid(False, which='minor', axis="x") ax.grid(True, which='major',color='#cccccc',linestyle='-', axis="y") ax.grid(True, which='minor',color='#eeeeee',linestyle='--', axis="y") plt.savefig("image.svg")