%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 = ['Engineering', 'Computer Science', 'Psychology', 'Biology', 'Physical Sciences', 'Math and Statistics']
fig = plt.figure(figsize=(18,3))
for sp in range(len(stem_cats)):
ax = fig.add_subplot(1,6,sp+1)
ax.plot(women_degrees['Year'], women_degrees[stem_cats[sp]], c=cb_dark_blue, label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[sp]], c=cb_orange, label='Men', linewidth=3)
for key,spine in ax.spines.items():
spine.set_visible(False)
ax.set_xlim(1968, 2011)
ax.set_ylim(0,100)
ax.set_title(stem_cats[sp])
ax.tick_params(bottom="off", top="off", left="off", right="off")
if sp == 0:
ax.text(2005, 87, 'Men')
ax.text(2002, 8, 'Women')
elif sp == 5:
ax.text(2005, 62, 'Men')
ax.text(2001, 35, 'Women')
plt.show()
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']
# Generate a 6 row by 3 column grid of subplots.
fig=plt.figure(figsize=(16,20))
# first column:stem_cats
for sp in range(len(stem_cats)):
ax=fig.add_subplot(6,3,3*sp+1)
ax.plot(women_degrees["Year"],women_degrees[stem_cats[sp]],c=cb_dark_blue,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[stem_cats[sp]],c=cb_orange,label="Men",linewidth=3)
for key,spine in ax.spines.items():
spine.set_visible(False)
ax.tick_params(top="off",bottom="off",left="off",right="off")
ax.set_title(stem_cats[sp])
ax.set_xlim(1968,2011)
ax.set_ylim(0,100)
if sp==0:
ax.text(2003,85,"Women")
ax.text(2005,10,"Men")
elif sp==5:
ax.text(2005,87,"Men")
ax.text(2003,7,"Women")
# second column:lib_arts_cats
for sp in range(len(lib_arts_cats)):
ax=fig.add_subplot(6,3,3*sp+2)
ax.plot(women_degrees["Year"],women_degrees[lib_arts_cats[sp]],c=cb_dark_blue,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[lib_arts_cats[sp]],c=cb_orange,label="Men",linewidth=3)
for key,spine in ax.spines.items():
spine.set_visible(False)
ax.set_xlim(1968,2011)
ax.set_ylim(0,100)
ax.set_title(lib_arts_cats[sp])
ax.tick_params(top="off",right="off",left="off",bottom="off")
if sp==0:
ax.text(2005,18,"Men")
ax.text(2003,78,"Women")
for sp in range(len(other_cats)):
ax=fig.add_subplot(6,3,3*sp+3)
ax.plot(women_degrees["Year"],women_degrees[other_cats[sp]],c=cb_dark_blue,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[other_cats[sp]],c=cb_orange,label="Men",linewidth=3)
ax.set_title(other_cats[sp])
ax.tick_params(top="off",bottom="off",left="off",right="off")
for key,spine in ax.spines.items():
spine.set_visible(False)
ax.set_xlim(1968, 2011)
ax.set_ylim(0,100)
if sp==0:
ax.text(2005,18,"Men")
ax.text(2003,91,"Women")
elif sp==5:
ax.text(2005,60,"Men")
ax.text(2003,30,"Women")
plt.show()
fig=plt.figure(figsize=(18,20))
# first column:stem_cats
for sp in range(len(stem_cats)):
ax=fig.add_subplot(6,3,3*sp+1)
ax.plot(women_degrees["Year"],women_degrees[stem_cats[sp]],c=cb_dark_blue,linewidth=3,label="Women")
ax.plot(women_degrees["Year"],100-women_degrees[stem_cats[sp]],c=cb_orange,linewidth=3,label="Men")
# add title
ax.set_title(stem_cats[sp])
# remove tick params' & xlabel (labelbottom)
ax.tick_params(top="off",bottom="off",left="off",right="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update x,y lim
ax.set_xlim(1968,2011)
ax.set_ylim(0,100)
# add lebel on fist & last gragh in the column
if sp==0:
ax.text(2007,27,"Men")
ax.text(2005,81,"Women")
elif sp==len(stem_cats)-1:
ax.text(2007,20,"Men")
ax.text(2005,87,"Women")
ax.tick_params(labelbottom="on")
# second column:lib_arts_cats
for sp in range(len(lib_arts_cats)):
ax=fig.add_subplot(6,3,3*sp+2)
ax.plot(women_degrees["Year"],women_degrees[lib_arts_cats[sp]],c=cb_orange,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[lib_arts_cats[sp]],c=cb_dark_blue,label="Men",linewidth=3)
# add title
ax.set_title(lib_arts_cats[sp])
# remove tick_params & labelbottom
ax.tick_params(top="off",right="off",left="off",bottom="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update xlim,ylim
ax.set_xlim(1968,2011)
ax.set_ylim(0,100)
# add label for first & last figure
if sp==0:
ax.text(2007,35,"Men")
ax.text(2005,75,"Women")
elif sp==len(lib_arts_cats)-1:
ax.tick_params(labelbottom="on")
# third column:other_cats
for sp in range(len(other_cats)):
ax=fig.add_subplot(6,3,3*sp+3)
ax.plot(women_degrees["Year"],women_degrees[other_cats[sp]],c=cb_orange,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[other_cats[sp]],c=cb_dark_blue,label="Men",linewidth=3)
# set title
ax.set_title(other_cats[sp])
# remove tick_params & labelbottom
ax.tick_params(top="off",bottom="off",left="off",right="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update xlim,ylim
ax.set_xlim(1968,2011)
ax.set_ylim(0,100)
# add label for first & last figure
if sp==0:
ax.text(2007,18,"Men")
ax.text(2005,90,"Women")
elif sp==len(other_cats)-1:
ax.text(2008,62,"Men")
ax.text(2005,32,"Women")
ax.tick_params(labelbottom="on")
plt.show()
fig=plt.figure(figsize=(18,20))
# first column:stem_cats
for sp in range(len(stem_cats)):
ax=fig.add_subplot(6,3,3*sp+1)
ax.plot(women_degrees["Year"],women_degrees[stem_cats[sp]],c=cb_dark_blue,linewidth=3,label="Women")
ax.plot(women_degrees["Year"],100-women_degrees[stem_cats[sp]],c=cb_orange,linewidth=3,label="Men")
# add title
ax.set_title(stem_cats[sp])
# remove tick params' & xlabel (labelbottom)
ax.tick_params(top="off",bottom="off",left="off",right="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update x,y lim
ax.set_xlim(1968,2011)
ax.set_yticks([0,100])
# add lebel on fist & last gragh in the column
if sp==0:
ax.text(2007,27,"Men")
ax.text(2005,81,"Women")
elif sp==len(stem_cats)-1:
ax.text(2007,20,"Men")
ax.text(2005,87,"Women")
ax.tick_params(labelbottom="on")
# second column:lib_arts_cats
for sp in range(len(lib_arts_cats)):
ax=fig.add_subplot(6,3,3*sp+2)
ax.plot(women_degrees["Year"],women_degrees[lib_arts_cats[sp]],c=cb_orange,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[lib_arts_cats[sp]],c=cb_dark_blue,label="Men",linewidth=3)
# add title
ax.set_title(lib_arts_cats[sp])
# remove tick_params & labelbottom
ax.tick_params(top="off",right="off",left="off",bottom="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update xlim,ylim
ax.set_xlim(1968,2011)
ax.set_yticks([0,100])
# add label for first & last figure
if sp==0:
ax.text(2007,35,"Men")
ax.text(2005,75,"Women")
elif sp==len(lib_arts_cats)-1:
ax.tick_params(labelbottom="on")
# third column:other_cats
for sp in range(len(other_cats)):
ax=fig.add_subplot(6,3,3*sp+3)
ax.plot(women_degrees["Year"],women_degrees[other_cats[sp]],c=cb_orange,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[other_cats[sp]],c=cb_dark_blue,label="Men",linewidth=3)
# set title
ax.set_title(other_cats[sp])
# remove tick_params & labelbottom
ax.tick_params(top="off",bottom="off",left="off",right="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update xlim,ylim
ax.set_xlim(1968,2011)
ax.set_yticks([0,100])
# add label for first & last figure
if sp==0:
ax.text(2007,18,"Men")
ax.text(2005,90,"Women")
elif sp==len(other_cats)-1:
ax.text(2008,62,"Men")
ax.text(2005,32,"Women")
ax.tick_params(labelbottom="on")
plt.show()
fig=plt.figure(figsize=(18,20))
# first column:stem_cats
for sp in range(len(stem_cats)):
ax=fig.add_subplot(6,3,3*sp+1)
ax.plot(women_degrees["Year"],women_degrees[stem_cats[sp]],c=cb_dark_blue,linewidth=3,label="Women")
ax.plot(women_degrees["Year"],100-women_degrees[stem_cats[sp]],c=cb_orange,linewidth=3,label="Men")
# add title
ax.set_title(stem_cats[sp])
# remove tick params' & xlabel (labelbottom)
ax.tick_params(top="off",bottom="off",left="off",right="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update x,y lim
ax.set_xlim(1968,2011)
# simplify y by set_yticks([0,100]) only those degree
ax.set_yticks([0,100])
# add horizontal line in 50 degree
ax.axhline(50,c=(171/255,171/255,171/255),alpha=0.3)
# add lebel on fist & last gragh in the column
if sp==0:
ax.text(2007,27,"Men")
ax.text(2005,81,"Women")
elif sp==len(stem_cats)-1:
ax.text(2007,20,"Men")
ax.text(2005,87,"Women")
ax.tick_params(labelbottom="on")
# second column:lib_arts_cats
for sp in range(len(lib_arts_cats)):
ax=fig.add_subplot(6,3,3*sp+2)
ax.plot(women_degrees["Year"],women_degrees[lib_arts_cats[sp]],c=cb_orange,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[lib_arts_cats[sp]],c=cb_dark_blue,label="Men",linewidth=3)
# add title
ax.set_title(lib_arts_cats[sp])
# remove tick_params & labelbottom
ax.tick_params(top="off",right="off",left="off",bottom="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update xlim,ylim
ax.set_xlim(1968,2011)
# simplify y by set_yticks([0,100]) only those degree
ax.set_yticks([0,100])
# add horizontal line in 50 degree
ax.axhline(50,c=(171/255,171/255,171/255),alpha=0.3)
# add label for first & last figure
if sp==0:
ax.text(2007,35,"Men")
ax.text(2005,75,"Women")
elif sp==len(lib_arts_cats)-1:
ax.tick_params(labelbottom="on")
# third column:other_cats
for sp in range(len(other_cats)):
ax=fig.add_subplot(6,3,3*sp+3)
ax.plot(women_degrees["Year"],women_degrees[other_cats[sp]],c=cb_orange,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[other_cats[sp]],c=cb_dark_blue,label="Men",linewidth=3)
# set title
ax.set_title(other_cats[sp])
# remove tick_params & labelbottom
ax.tick_params(top="off",bottom="off",left="off",right="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update xlim,ylim
ax.set_xlim(1968,2011)
# simplify y by set_yticks([0,100]) only those degree
ax.set_yticks([0,100])
# add horizontal line at 50 degree
ax.axhline(50,c=(171/255,171/255,171/255),alpha=0.3)
# add label for first & last figure
if sp==0:
ax.text(2007,18,"Men")
ax.text(2005,90,"Women")
elif sp==len(other_cats)-1:
ax.text(2008,62,"Men")
ax.text(2005,32,"Women")
ax.tick_params(labelbottom="on")
plt.show()
fig=plt.figure(figsize=(18,20))
# first column:stem_cats
for sp in range(len(stem_cats)):
ax=fig.add_subplot(6,3,3*sp+1)
ax.plot(women_degrees["Year"],women_degrees[stem_cats[sp]],c=cb_dark_blue,linewidth=3,label="Women")
ax.plot(women_degrees["Year"],100-women_degrees[stem_cats[sp]],c=cb_orange,linewidth=3,label="Men")
# add title
ax.set_title(stem_cats[sp])
# remove tick params' & xlabel (labelbottom)
ax.tick_params(top="off",bottom="off",left="off",right="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update x,y lim
ax.set_xlim(1968,2011)
# simplify y by set_yticks([0,100]) only those degree
ax.set_yticks([0,100])
# add horizontal line in 50 degree
ax.axhline(50,c=(171/255,171/255,171/255),alpha=0.3)
# add lebel on fist & last gragh in the column
if sp==0:
ax.text(2007,27,"Men")
ax.text(2005,81,"Women")
elif sp==len(stem_cats)-1:
ax.text(2007,20,"Men")
ax.text(2005,87,"Women")
ax.tick_params(labelbottom="on")
# second column:lib_arts_cats
for sp in range(len(lib_arts_cats)):
ax=fig.add_subplot(6,3,3*sp+2)
ax.plot(women_degrees["Year"],women_degrees[lib_arts_cats[sp]],c=cb_orange,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[lib_arts_cats[sp]],c=cb_dark_blue,label="Men",linewidth=3)
# add title
ax.set_title(lib_arts_cats[sp])
# remove tick_params & labelbottom
ax.tick_params(top="off",right="off",left="off",bottom="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update xlim,ylim
ax.set_xlim(1968,2011)
# simplify y by set_yticks([0,100]) only those degree
ax.set_yticks([0,100])
# add horizontal line in 50 degree
ax.axhline(50,c=(171/255,171/255,171/255),alpha=0.3)
# add label for first & last figure
if sp==0:
ax.text(2007,35,"Men")
ax.text(2005,75,"Women")
elif sp==len(lib_arts_cats)-1:
ax.tick_params(labelbottom="on")
# third column:other_cats
for sp in range(len(other_cats)):
ax=fig.add_subplot(6,3,3*sp+3)
ax.plot(women_degrees["Year"],women_degrees[other_cats[sp]],c=cb_orange,label="Women",linewidth=3)
ax.plot(women_degrees["Year"],100-women_degrees[other_cats[sp]],c=cb_dark_blue,label="Men",linewidth=3)
# set title
ax.set_title(other_cats[sp])
# remove tick_params & labelbottom
ax.tick_params(top="off",bottom="off",left="off",right="off",labelbottom="off")
# remove border
for key,spine in ax.spines.items():
spine.set_visible(False)
# update xlim,ylim
ax.set_xlim(1968,2011)
# simplify y by set_yticks([0,100]) only those degree
ax.set_yticks([0,100])
# add horizontal line at 50 degree
ax.axhline(50,c=(171/255,171/255,171/255),alpha=0.3)
# add label for first & last figure
if sp==0:
ax.text(2007,18,"Men")
ax.text(2005,90,"Women")
elif sp==len(other_cats)-1:
ax.text(2008,62,"Men")
ax.text(2005,32,"Women")
ax.tick_params(labelbottom="on")
# save file as png
fig.savefig("gender_degrees.png")
plt.show()