fig = plt.figure(figsize=(16, 20))
## Generate first column of line charts. STEM degrees.
for sp in range(0,18,3):
cat_index = int(sp/3)
ax = fig.add_subplot(6,3,sp+1)
ax.plot(women_degrees['Year'], women_degrees[stem_cats[cat_index]], c=cb_dark_blue, label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[cat_index]], 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[cat_index])
ax.tick_params(bottom="off", top="off", left="off", right="off")
if cat_index == 0:
ax.text(2003, 85, 'Women')
ax.text(2005, 10, 'Men')
elif cat_index == 5:
ax.text(2005, 87, 'Men')
ax.text(2003, 7, 'Women')
## Generate second column of line charts. Liberal arts degrees.
for sp in range(1,16,3):
cat_index = int((sp-1)/3)
ax = fig.add_subplot(6,3,sp+1)
ax.plot(women_degrees['Year'], women_degrees[lib_arts_cats[cat_index]], c=cb_dark_blue, label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[lib_arts_cats[cat_index]], 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[cat_index])
ax.tick_params(bottom="off", top="off", left="off", right="off")
if cat_index == 0:
ax.text(2003, 78, 'Women')
ax.text(2005, 18, 'Men')
## Generate third column of line charts. Other degrees.
for sp in range(2,20,3):
cat_index = int((sp-2)/3)
ax = fig.add_subplot(6,3,sp+1)
ax.plot(women_degrees['Year'], women_degrees[other_cats[cat_index]], c=cb_dark_blue, label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[other_cats[cat_index]], 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(other_cats[cat_index])
ax.tick_params(bottom="off", top="off", left="off", right="off")
if cat_index == 0:
ax.text(2003, 90, 'Women')
ax.text(2005, 5, 'Men')
elif cat_index == 5:
ax.text(2005, 62, 'Men')
ax.text(2003, 30, 'Women')
plt.show()
I am currently working on one of the Metplotlib guided projects and spent little over an hour trying to figure it out until I ended up looking at the solution. This is the most lost I’ve been in this course so far. I do not understand how the range
is working in this manner as well as the cat_index
. If someone could help me understand just what this is doing, and how I could of figured this out on my own. Maybe I missed it in the course but I don’t remember learning it in this manner. I tried looking into the documentation before looking into the solution but was not successful. How could I have figured this out on my own?