Hey there Robert! Welcome to the community!

Do remember to mark a solution as “Solved” if it answers your question (this helps other students find the post!)

This is correct. Let’s look at the code you’re trying to wrap your head around:

```
for sp in range(0,18,3):
cat_index = int(sp/3)
ax = fig.add_subplot(6,3,sp+1)
```

Let’s break this down line by line:

## First line

```
for sp in range(0,18,3):
```

`range(0,18,3)`

can be thought of as a list containing the following: `[0, 3, 6, 9, 12, 15]`

You’re essentially iterating over these 6 values in the list. In the first iteration, `sp`

is 0, in the second it’s 3, etc.

We’ll touch on why this matters down below.

## Second Line

```
cat_index = int(sp/3)
```

So above, we saw how `sp`

takes the values 0, 3, 6, 9, etc. `cat_index`

, after the division by 3, therefore works out to the values 0, 1, 2, 3, etc.

If you look below in the solutions, this `cat_index`

value is used to index the list of major categories, like so:

`women_degrees[stem_cats[cat_index]]`

Where `women_degrees`

was the csv file you read in initially, and `stem_cats`

is the following list of STEM majors.

##
stem_cats

`stem_cats = ['Psychology', 'Biology', 'Math and Statistics', 'Physical Sciences', 'Computer Science', 'Engineering']`

`stem_cats[cat_index]`

therefore indexes the first element in the list when sp = 0, it indexes the second element when sp = 3 (because sp is divided by 3 to calculate `cat_index`

), and so on!

## Third Line

```
ax = fig.add_subplot(6,3,sp+1)
```

Here, you’re adding a sub-plot to the figure. Again, keep in mind the values that sp takes on during each iteration (0, 3, 6, etc).

During the first iteration, when sp = 0, the code works out to: `ax = fig.add_subplot(6,3,1)`

In `fig.add_subplot()`

, the first parameter is the number of rows of the figure, the second parameter is the number of columns, and the 3rd parameter (the one that changes depending on sp in our case) is the position of the sub-plot in the figure. In this case, for sp = 0, its position will be “1”. When sp is 3, its position will be “4”, which would place the 2nd subplot just below the first one.

In an earlier mission, it’s explained to you how the sub-plot positions are mapped out on a figure.

In a 3x3 figure containing 9 sub-plots, the sub-plots would be positioned like so:

1, 2, 3

4, 5, 6

7, 8, 9

Notice that sub-plot 4 is right below sub-plot 1, and sub-plot 7 is right below sub-plot 4. This is how the difference of 3 in the `sp`

variable helps you position graphs belonging to the same category of major in the same column in the figure. In the case of the code you linked, we’re plotting all the graphs for the STEM majors in the very first column.

In the solutions, the `sp`

variable is altered like that to plot graphs in different positions.

Again, refer to the above 3x3 figure example. If you didn’t want to plot your sub-plots in positions 1, 4, and 7, and you instead wanted positions 2, 5, and 8, you’d have to use a different strategy to refer to them. You could once again generate a range of sp values with intervals of 3, and then instead of adding 1, you could subtract 1, or subtract 2, to refer to the position you want.

My solution to this project involved a slightly different approach, where I didn’t generate a range of `sp`

values in intervals of 3, but the concept is the same.