Visualizing The Gender Gap In College Degrees - Need explanation about code at step 2

Screen Link: https://app.dataquest.io/m/149/guided-project%3A-visualizing-the-gender-gap-in-college-degrees/2/comparing-across-all-degrees

I got stuck and looked at the solutions:

## Generate first column of line charts. STEM degrees.
for sp in range(0,18,3):
    cat_index = int(sp/3) #NOT CLEAR WHY / by 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')

Then I just copied the solution’s code on my jupyterlab. I am not able to understand the code yet and, anyway, it does not work on my python version (the latest)

I dont’t undestand why :

cat_index = int(sp/3) 

# and then 

ax.plot(women_degrees['Year'],
            women_degrees[stem_cats[cat_index]], 
            c=cb_dark_blue, label='Women', linewidth=3)

In my newbie head, the first ‘sp’ is 1, or at least it would be if I perform

for sp in range(0,6):
    print(sp+1)

So, the first ‘cat_index’ in the loop should be equal to 1/3 (“women_degrees[stem_cats[0.33333…]]”???)

Also, I don’t understand why ranges are changing in the 3 for loops.

Anyway, on my jupyter notebok, I get a long warning message and no result

anaconda3\lib\site-packages\ipykernel_launcher.py:47: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.

Could it be related to the gap between my python version and Dataquest platform’s one ?

Finally, won’t be just easier and more practical to use a unique list with all the degrees ?

Many thanks to consider this request of clarification, I spent a significant amount of time trying to understand the solution code and would really need to understand

No way to be sure without seeing all of your code. A warning shouldn’t really stop the output from displaying. It is just as likely that you didn’t include the %matplotlib inline in any of the code cells and that’s why the plots are not displaying. This is probably more so because of your code.

Because of this range(0,18,3). I would recommend checking out the documentation for range first to see whether that helps you understand what’s happening or not.