import pandas as pd
import re
import numpy as np
from IPython.display import display
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
from matplotlib import rcParams
from functions import *
plt.rcParams.update({'axes.titlepad': 20, 'font.size': 12, 'axes.titlesize':20})
colors = [(0/255,107/255,164/255), (255/255, 128/255, 14/255), 'red', 'green']
women_degrees = pd.read_csv('./data/percent-bachelors-degrees-women-usa.csv')
display(women_degrees.iloc[:5,:10])
cb_dark_blue = (0/255,107/255,164/255)
cb_orange = (255/255, 128/255, 14/255)
stem_cats = ['Engineering', 'Computer Science', 'Physical Sciences', 'Math and Statistics', 'Biology', 'Psychology']
fig = plt.figure(figsize=(18,3))
for sp, element in enumerate(stem_cats):
ax = fig.add_subplot(1,6,sp+1)
ax.plot(women_degrees['Year'], women_degrees[element], label='Women', c=cb_dark_blue, linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[element], label='Men', c=cb_orange, linewidth=3)
#axis mods
for key, spine in ax.spines.items():
spine.set_visible(False)
ax.tick_params(left=False, right=False, top=False, bottom=False)
ax.set_xlim(1968, 2011); ax.set_ylim(0,100)
ax.set_title(element)
#Anotations
if(sp==0):
ax.text(2003, 70, 'Men')
ax.text(1999, 28, 'Women')
elif(sp==5):
ax.text(2000, 65, 'Women')
ax.text(2004, 30, 'Men')
#fig.suptitle("Gender", fontsize=16)
fig.suptitle("Gender Balance in US STEM Degrees", x=0.38, y=1.12, horizontalalignment='left', verticalalignment='top', fontsize = 16)
plt.show()
We will now look at the 17 degrees available (using a subplot grid layout of 6 rows by 3 columns) while grouping the degrees into STEM, liberal arts, and other.
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_grey = (171/255, 171/255, 171/255)
fig = plt.figure(figsize=(12,18))
def make_degree_plot(ax, women_degrees, sp, element):
ax.plot(women_degrees['Year'], women_degrees[element], label='Women', c=cb_dark_blue, linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[element], label='Men', c=cb_orange, linewidth=3)
#axis mods
for key, spine in ax.spines.items():
spine.set_visible(False)
#labelbottom='off' - removes the labels from the ticks
ax.tick_params(left=False, right=False, top=False, bottom=False, labelbottom=False)
ax.set_xlim(1968, 2011); ax.set_ylim(0,100)
ax.set_title(element)
#Axes.set_yticks() specifies which labels to display
ax.set_yticks([0,100])
#Axes.axhline() creates an horizontal line
ax.axhline(50, c=cb_grey, alpha=0.3)
#Anotations
if(element == 'Psychology'):
ax.text(2005, 10, 'Men')
ax.text(2002, 82, 'Women')
elif(element == 'Engineering'):
ax.text(2005, 90, 'Men')
ax.text(2002, 5, 'Women')
elif(element == 'Foreign Languages'):
ax.text(2005, 20, 'Men')
ax.text(2002, 80, 'Women')
elif(element == 'Health Professions'):
ax.text(2005, 5, 'Men')
ax.text(2002, 90, 'Women')
elif(element == 'Architecture'):
ax.text(2005, 65, 'Men')
ax.text(2002, 30, 'Women')
for sp, element in enumerate(stem_cats):
ax = fig.add_subplot(6,3,sp*3+1)
make_degree_plot(ax, women_degrees, sp, element)
ax.tick_params(labelbottom=True)
for sp, element in enumerate(lib_arts_cats):
ax = fig.add_subplot(6,3,sp*3+2)
make_degree_plot(ax, women_degrees, sp, element)
ax.tick_params(labelbottom=True)
for sp, element in enumerate(other_cats):
ax = fig.add_subplot(6,3,sp*3+3)
make_degree_plot(ax, women_degrees, sp, element)
ax.tick_params(labelbottom=True)
plt.show()
fig.savefig("fig_project051_gender_gap.pdf")