%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
women_degrees = pd.read_csv('percent-bachelors-degrees-women-usa.csv')
# Setting color for plot
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)
# Clear the spines on the chart
for key,spine in ax.spines.items():
spine.set_visible(False)
# Set the limit and title
ax.set_xlim(1968, 2011)
ax.set_ylim(0,100)
ax.set_title(stem_cats[sp])
# Delete ticks on the spines in the chart
ax.tick_params(bottom="off", top="off", left="off", right="off")
#Add the notations
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']
# Setting the length for each list
a, b, c = len(stem_cats), len(lib_arts_cats), len(other_cats)
# Setting the colours
dark_blue = (0/255,107/255,164/255)
orange = (255/255, 128/255, 14/255)
fig = plt.figure(figsize=(9,18))
# Plot the charts
for sp in range(0,17):
# stem_cats
if sp < a:
# Pos of each grid & sketch the plot
ax = fig.add_subplot(a,1,sp+1)
ax.plot(women_degrees['Year'], women_degrees[stem_cats[sp]], c=dark_blue,
label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[sp]], c=orange,
label='Men', linewidth=3)
# Clear ticks on spines first & the spines on chart
ax.tick_params(top='off',bottom='off',left='off',right='off')
for key,spines in ax.spines.items():
spines.set_visible(False)
# Set limits each axis & title
ax.set_xlim(1970, 2010)
ax.set_ylim(0, 100)
ax.set_title(stem_cats[sp])
# Clear the annotations
if sp == 0:
ax.text(2005, 83, 'Women')
ax.text(2008, 10, 'Men')
if sp == (a-1):
ax.text(2002, 7, 'Women')
ax.text(2005, 90, 'Men')
# lib_arts_cats
elif (sp >= a) & (sp < a+b):
# Pos of each grid & sketch the plot
ax = fig.add_subplot(b,2,sp+1)
ax.plot(women_degrees['Year'], women_degrees[lib_arts_cats[sp]], c=dark_blue,
label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[lib_arts_cats[sp]], c=orange,
label='Men', linewidth=3)
# Clear ticks on spines first & the spines on chart
ax.tick_params(top='off',bottom='off',left='off',right='off')
for key,spines in ax.spines.items():
spines.set_visible(False)
# Set limits each axis & title
ax.set_xlim(1970, 2010)
ax.set_ylim(0, 100)
ax.set_title(lib_arts_cats[sp])
# Clear the annotations
if sp == a:
ax.text(2005, 80, 'Women')
ax.text(2005, 20, 'Men')
# if sp == (a+b-1):
# ax.text(2005, 7, 'Women')
# ax.text(2005, 90, 'Men')
# other_cats
else: break
IndexErrorTraceback (most recent call last) <ipython-input-11-c58c21685d14> in <module>() 43 # Pos of each grid & sketch the plot 44 ax = fig.add_subplot(b,2,sp+1) ---> 45 ax.plot(women_degrees['Year'], women_degrees[lib_arts_cats[sp]], c=dark_blue, 46 label='Women', linewidth=3) 47 ax.plot(women_degrees['Year'], 100-women_degrees[lib_arts_cats[sp]], c=orange, IndexError: list index out of range
%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
women_degrees = pd.read_csv('percent-bachelors-degrees-women-usa.csv')
women_degrees.describe()
Year | Agriculture | Architecture | Art and Performance | Biology | Business | Communications and Journalism | Computer Science | Education | Engineering | English | Foreign Languages | Health Professions | Math and Statistics | Physical Sciences | Psychology | Public Administration | Social Sciences and History | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
count | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 | 42.000000 |
mean | 1990.500000 | 33.848165 | 33.685540 | 61.100000 | 49.429864 | 40.653471 | 56.216667 | 25.809524 | 76.356236 | 12.892857 | 66.186680 | 71.723810 | 82.983333 | 44.478571 | 31.304762 | 68.776190 | 76.085714 | 45.407143 |
std | 12.267844 | 12.552731 | 9.574057 | 1.305336 | 10.087725 | 13.116109 | 8.698610 | 6.688753 | 2.212641 | 5.670824 | 1.950990 | 1.926682 | 2.914967 | 2.646262 | 9.000866 | 9.705463 | 5.879504 | 4.763653 |
min | 1970.000000 | 4.229798 | 11.921005 | 58.600000 | 29.088363 | 9.064439 | 35.300000 | 13.600000 | 72.166525 | 0.800000 | 61.647206 | 69.000000 | 75.500000 | 38.000000 | 13.800000 | 44.400000 | 62.600000 | 36.100000 |
25% | 1980.250000 | 30.840814 | 28.520709 | 60.200000 | 44.311821 | 37.390851 | 55.125000 | 19.125000 | 74.994573 | 10.625000 | 65.583807 | 70.125000 | 81.825000 | 42.875000 | 24.875000 | 65.550000 | 74.625000 | 43.825000 |
50% | 1990.500000 | 33.317552 | 35.994852 | 61.300000 | 50.971469 | 47.210123 | 59.850000 | 27.300000 | 75.937020 | 14.100000 | 66.112018 | 71.150000 | 83.700000 | 44.900000 | 32.100000 | 72.750000 | 77.450000 | 45.300000 |
75% | 2000.750000 | 45.663953 | 40.790605 | 62.000000 | 58.679194 | 48.876139 | 62.125000 | 29.775000 | 78.619420 | 16.950000 | 67.861247 | 73.875000 | 85.175000 | 46.500000 | 40.200000 | 76.925000 | 81.100000 | 49.375000 |
max | 2011.000000 | 50.037182 | 44.499331 | 63.400000 | 62.169456 | 50.552335 | 64.600000 | 37.100000 | 79.618625 | 19.000000 | 68.894487 | 75.300000 | 86.500000 | 48.300000 | 42.200000 | 77.800000 | 82.100000 | 51.800000 |
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']
# Setting the length for each list
a, b, c = len(stem_cats), len(lib_arts_cats), len(other_cats)
# Setting the colours
dark_blue = (0/255,107/255,164/255)
orange = (255/255, 128/255, 14/255)
fig = plt.figure(figsize=(12,24))
# Create flag for each grid
num_grid = 0
for row in range(0,6):
for sp in range(0,3):
if num_grid == 16:
num_grid += 1
continue
# Pos of each grid & sketch the plot & set title
if sp == 0: # stem_cats
ax = fig.add_subplot(6,3,num_grid+1)
ax.plot(women_degrees['Year'], women_degrees[stem_cats[row]], c=dark_blue,
label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[row]], c=orange,
label='Men', linewidth=3)
ax.set_title(stem_cats[row])
num_grid += 1
elif sp == 1: # lib_arts_cats
ax = fig.add_subplot(6,3,num_grid+1)
ax.plot(women_degrees['Year'], women_degrees[lib_arts_cats[row]], c=dark_blue,
label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[lib_arts_cats[row]], c=orange,
label='Men', linewidth=3)
ax.set_title(lib_arts_cats[row])
num_grid += 1
else: # other_cats
ax = fig.add_subplot(6,3,num_grid+1)
ax.plot(women_degrees['Year'], women_degrees[other_cats[row]], c=dark_blue,
label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[other_cats[row]], c=orange,
label='Men', linewidth=3)
ax.set_title(other_cats[row])
num_grid += 1
# Clear ticks on spines first & the spines on chart
ax.tick_params(top='off',bottom='off',left='off',right='off',
labelbottom='off')
# Only displays 0, 100 on y_axis
ax.set_yticks([0, 100])
# Sketch a horizontal line a cross the 50 y_axis
ax.axhline(50, c=(171/255,171/255,171/255), alpha=0.3)
for key,spines in ax.spines.items():
spines.set_visible(False)
# Set limits each axis & title
ax.set_xlim(1970, 2010)
ax.set_ylim(0, 100)
# Set the annotations
if num_grid == 1:
ax.text(2005, 82, 'Women')
ax.text(2008, 12, 'Men')
elif num_grid == 2:
ax.text(2005, 73, 'Women')
ax.text(2005, 25, 'Men')
elif num_grid == 3:
ax.text(2005, 90, 'Women')
ax.text(2005, 9, 'Men')
elif num_grid == 16:
ax.text(2005, 7, 'Women')
ax.text(2005, 90, 'Men')
elif num_grid == 18:
ax.text(2005, 30, 'Women')
ax.text(2005, 67, 'Men')
else: continue
ax.tick_params(labelbottom='on')
plt.savefig('gender_degrees.png')
plt.get_backend()
'module://ipykernel.pylab.backend_inline'
women_degrees.shape
(42, 18)