import numpy as np
import matplotlib.pyplot as plt
from cycler import cycler
import pandas as pd
import matplotlib. patches as mpatches
from matplotlib. lines import Line2D
df = pd.read_csv("male.tsv", index_col=0 , sep = "\t").T
df = df.fillna(method = 'ffill')
df2 = pd.read_csv("female.tsv", index_col=0 , sep = "\t").T
df2 = df2.fillna(method = 'ffill')
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = ['Noto Sans Display']
plt.rcParams["axes.prop_cycle"] = plt.cycler("color", plt.get_cmap("tab20")(np.linspace(0,1,12)))
fig, ax = plt.subplots(figsize=(12, 8))
ax2 = ax.twinx()
plt.subplots_adjust(left=0.07, bottom=0.16, right=0.97, top=0.95)
ax.plot(df, lw=2)
ax2.plot(df2,ls="-.", lw=2)
ax.legend(df.columns, fontsize=10, ncol=8, loc='center' ,bbox_to_anchor=(0, -0.18, 1, 0.102), frameon=True, facecolor="#eeeeee")
ax.set_axisbelow(True)
ax.set_ylabel("Percentage", fontsize=15)
ax.grid(which='major',color='#aaaaaa',linestyle='-', axis="y")
ax.margins(0.02)
ax.set_ylim([50,90])
ax2.set_ylim([50,90])
plt.title("Labour force participation rate (15-64 age) by Sex, (OECD Stats)", fontsize=18)
plt.setp(ax.get_xticklabels(), fontsize=9, rotation=30)
#define patches and lines to add to legend
handles, labels = plt.gca().get_legend_handles_labels ()
line1 = Line2D([0], [0], label='Male', lw=1)
line2 = Line2D([0], [0], label='Female', ls='-.', lw=2)
#add handles
handles.extend([line1, line2])
ax2.legend(handles=handles, loc="upper left", facecolor="#eeeeee" , ncol=2)
ax2.set_yticklabels([])
ax2.set_yticks([])
plt.savefig("image.svg")