In [1]:
%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
'''
Let's make plots for 5 stem categories and describe percent of degrees granted to each gender during some period(in years)
We want to plot each degree-gender category percentage next to each other, all in one row
We want to make end gender gaps sorted in decreasing manner
'''
women_degrees = pd.read_csv('percent-bachelors-degrees-women-usa.csv')
#tuples that define color for each line (men and women) in RGB values
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(0,6):
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)
#set all four spines(left,right,top,bottom) to unvisible to improve data-ink ratio
for key,value in ax.spines.items():
value.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')
In [3]:
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']
cb_dark_blue = (0/255,107/255,164/255)
cb_orange = (255/255, 128/255, 14/255)
cb_y_midline = (177/255,177/255,177/255)
figure = plt.figure(figsize=(9,20))
for i in range(0,len(stem_cats)):
ax = figure.add_subplot(6,3,i*3 + 1)
#plot line for women degree percentage
ax.plot(women_degrees['Year'], women_degrees[stem_cats[i]], c=cb_dark_blue, linewidth=3)
#plot line for men degree percentage ( 100 - women)
ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[i]], c=cb_orange, linewidth=3)
#we wont turn off labels on left side of plot for this column cuz its elements are first displayed in each row
#other columns elements have labels on left side off
ax.tick_params(bottom='off', top='off', left='off', right='off', labelbottom='off')
ax.set_title(stem_cats[i])
ax.set_xlim(1968,2011)
ax.set_ylim(0,100)
#draw mid line, where gender percentages are equal
ax.axhline(y=50, c=cb_y_midline, alpha=0.3)
# reduce y ticks(percentage) to just 2
ax.set_yticks([0,100])
# set spines to unvisible
for key,val in ax.spines.items():
val.set_visible(False)
if i == 0:
ax.text(2005, 80, 'Women')
ax.text(1998, 15, 'Man')
elif i == len(stem_cats)-1:
ax.text(2005, 72, 'Men')
ax.text(2004, 25, 'Women')
#we should turn x labels for the last row
ax.tick_params(labelbottom='on')
for i in range(0,len(lib_arts_cats)):
ax = figure.add_subplot(6,3,i*3 + 2)
#plot line for women degree percentage
ax.plot(women_degrees['Year'], women_degrees[lib_arts_cats[i]], c=cb_dark_blue, linewidth=3)
#plot line for men degree percentage ( 100 - women)
ax.plot(women_degrees['Year'], 100-women_degrees[lib_arts_cats[i]], c=cb_orange, linewidth=3)
ax.tick_params(bottom='off', top='off', left='off', right='off', labelbottom='off', labelleft='off')
ax.set_title(lib_arts_cats[i])
ax.set_xlim(1968,2011)
ax.set_ylim(0,100)
#draw mid line, where gender percentages are equal
ax.axhline(y=50, c=cb_y_midline, alpha=0.3)
# reduce y ticks(percentage) to just 2
ax.set_yticks([0,100])
for key,val in ax.spines.items():
val.set_visible(False)
if i == 0:
ax.text(2005, 80, 'Women')
ax.text(1998, 15, 'Men')
elif i==len(lib_arts_cats)-1:
#we should turn x labels for the last row
ax.tick_params(labelbottom='on')
for i in range(0,len(other_cats)):
ax = figure.add_subplot(6,3,i*3 + 3)
#plot line for women degree percentage
ax.plot(women_degrees['Year'], women_degrees[other_cats[i]], c=cb_dark_blue, linewidth=3)
#plot line for men degree percentage ( 100 - women)
ax.plot(women_degrees['Year'], 100-women_degrees[other_cats[i]], c=cb_orange, linewidth=3)
ax.tick_params(bottom='off', top='off', left='off', right='off', labelbottom='off',labelleft='off')
ax.set_title(other_cats[i])
ax.set_xlim(1968,2011)
ax.set_ylim(0,100)
#draw mid line, where gender percentages are equal
ax.axhline(y=50, c=cb_y_midline, alpha=0.3)
# reduce y ticks(percentage) to just 2
ax.set_yticks([0,100])
for key,val in ax.spines.items():
val.set_visible(False)
if i == 0:
ax.text(2005, 75, 'Women')
ax.text(2001, 20, 'Men')
elif i == len(other_cats)-1:
ax.text(2005, 72, 'Men')
ax.text(2004, 25, 'Women')
#we should turn x labels for the last row
ax.tick_params(labelbottom='on')
# export plots show on the figure to png file
figure.savefig('gender_degrees.png')
In [ ]: