In [14]:
%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt

women_degrees = pd.read_csv('percent-bachelors-degrees-women-usa.csv')
cb_dark_blue = (0/255,107/255,164/255)
cb_orange = (255/255, 128/255, 14/255)
stem_cats = ['Psychology', 'Biology', 'Math and Statistics', 'Physical Sciences', 'Computer Science', 'Engineering']
lib_arts_cats = ['Foreign Languages', 'English', 'Communications and Journalism', 'Art and Performance', 'Social Sciences and History']
other_cats = ['Health Professions', 'Public Administration', 'Education', 'Agriculture','Business', 'Architecture']
cat = len(stem_cats)+len(lib_arts_cats)+len(other_cats)
total=[stem_cats,lib_arts_cats,other_cats]
fig,ax = plt.subplots(6,3,figsize=(16, 20))
for n in range(0,len(total)):
    for sp in range(0,len(total[n])):
        ax[sp,n].plot(women_degrees['Year'], women_degrees[total[n][sp]], c=cb_dark_blue, label='Women', linewidth=3)
        ax[sp,n].plot(women_degrees['Year'], 100-women_degrees[total[n][sp]], c=cb_orange, label='Men', linewidth=3)
        for key,spine in ax[sp,n].spines.items():
            spine.set_visible(False)
        ax[sp,n].set_xlim(1968, 2011)
        ax[sp,n].set_ylim(0,100)
        ax[sp,n].set_title(total[n][sp])
        ax[sp,n].tick_params(bottom="off", top="off", left="off", right="off",labelbottom='off')
        ax[sp,n].set_yticks([0,100])
        ax[sp,n].axhline(50, c=(171/255, 171/255, 171/255), alpha=0.3)
        if sp == 0 and women_degrees[total[n][sp]].iloc[-1] > 50:
            ax[sp,n].text(2005, int(women_degrees[total[n][sp]].iloc[-1])+6, 'Women')
            ax[sp,n].text(2005, int(100-women_degrees[total[n][sp]].iloc[-1])-9, 'Men')
        elif sp == 0 and women_degrees[total[n][sp]].iloc[-1] < 50:
            ax[sp,n].text(2005, int(100-women_degrees[total[n][sp]].iloc[-1])+6, 'Men')
            ax[sp,n].text(2005, int(women_degrees[total[n][sp]].iloc[-1])-9, 'Women')
        elif sp == 5 and women_degrees[total[n][sp]].iloc[-1] > 50:
            ax[sp,n].text(2005, int(women_degrees[total[n][sp]].iloc[-1])+6, 'Women')
            ax[sp,n].text(2005, int(100-women_degrees[total[n][sp]].iloc[-1])-9, 'Men')
        elif sp == 5 and women_degrees[total[n][sp]].iloc[-1] < 50:
            ax[sp,n].text(2005, int(100-women_degrees[total[n][sp]].iloc[-1])+6, 'Men')
            ax[sp,n].text(2005, int(women_degrees[total[n][sp]].iloc[-1])-9, 'Women')        
        elif sp == (len(total[n])-1) and sp < 5 and women_degrees[total[n][sp]].iloc[-1] < 50 :
            fig.delaxes(ax[sp+1,n])
            ax[sp,n].text(2005, int(100-women_degrees[total[n][sp]].iloc[-1])+6, 'Men')
            ax[sp,n].text(2005, int(women_degrees[total[n][sp]].iloc[-1])-9, 'Women')        
        elif sp == (len(total[n])-1) and sp < 5 and women_degrees[total[n][sp]].iloc[-1] > 50 :
            fig.delaxes(ax[sp+1,n])
            ax[sp,n].text(2005, int(100-women_degrees[total[n][sp]].iloc[-1])+6, 'Women')
            ax[sp,n].text(2005, int(women_degrees[total[n][sp]].iloc[-1])-9, 'Men')   
fig.savefig("gender_degrees.png")
plt.show()