Visualizing The Gender Gap In College Degrees: Something I learned & a question to be answered

Something new I learned:
You can add subplots in separate cells, and call fig at the end of each cell to see the plots.

I did google but couldn’t find an answer. Does anyone know if there is a shortcut to turn off ticks on all axes instead of turning them off one by one? It’s not an unbearable inconvenience to list ‘top’, ‘bottom’, ‘left’, ‘right’ every time, but hey, laziness is what motivates us to program, right? :crazy_face:

Guided Project_ Visualizing The Gender Gap In College Degrees.ipynb (352.6 KB)

Click here to view the jupyter notebook file in a new tab

Nice buddy. :+1:t5:

This snippet might help in removing the yticks:

from matplotlib import pyplot as plt

plt.yticks([ ])

1 Like

Thanks for the comment!

I probably didn’t describe my question too well. I give plt.yticks([]) a try and it does disable the ticks, but along with the labels, which I do want to keep.

I did just find another way – Axes.tick_params(axis='both', which='both', length=0) – to achieve the same thing as Axes.tick_params(top = 'off', bottom = 'off', left = 'off', right = 'off'). This turns off all ticks without turning off the labels. Can’t say it’s much of an improvement though. :sweat_smile:

1 Like

Great then. In short, work should get done. :smile:

1 Like

Hi @veratsien,

Thanks for sharing your findings. I had wondered if there was a way to make the ticks longer or shorter. I tried your code

and saw that it also worked without the ‘which’ argument, or without the ‘axis’ argument. They seem to be interchangeable.
By the way, this is what happened when I set the length to be 100 :grin:


Glad to be of help!

I did some digging after seeing your comment. Here’s what I found:

  • Thanks to your comment I noticed in the Matplotlib doc that the default value for axis is 'both', and the default value for which is 'major'. Which does give a shortcut – Axes.tick_params(length=0) – for my original question, if the minor tick is not enabled. Yayyyyy! Thank you thank you!

  • Matplotlib doc on tick_params defines the axis parameter as axis{'x', 'y', 'both'} Axis on which to operate; default is 'both'.

  • Defines the which parameter as which{'major', 'minor', 'both'} Default is 'major'; apply arguments to which ticks.
    ‘Which’ isn’t very clear on what exactly is 'major' and 'minor'. :thinking:


So I did a little more digging and found out that 'major' ticks are the ones in black below, and 'minor' ticks are the ones in red below:
Exploration on _major & _minor ticks
So minor ticks are the ticks in between major ones that give more precision.

From what I read so far, to use minor ticks you’d have to give it data source and set it to True in set_xticks / set_yticks first. Here’s the code that generates the plot above. Play with it if you want:

t = np.arange(0.0, 100.0, 1)
s = np.sin(2 * np.pi * t) * np.exp(-t * 0.01)

fig, ax = plt.subplots()
ax.plot(t, s)
ax.set_xticks(ticks = t, minor = True)
ax.set_yticks(ticks = s, minor = True)
ax.tick_params(axis = 'x', which='minor', length=4, color='r')

Thanks again for your comment, I love how we are inspired to learn new things here. :hugs:


They were both unnecessary! I guess your solution was hiding in plain sight. There’s so much to learn in the different docs :sweat_smile:. I never even considered minor ticks.

Thanks for sharing the code for the line chart. I like how most of the ticks on the y-axis cluster between 0 and 1, clearly showing where most of the values fall.

Yes, the DQ community is really good. I’ve learnt so much, and I’ve just learnt something new here :smiling_face_with_three_hearts:

By the way, for the plot in my previous comment, the (tick) length was 100, not zero. That was a mistake. The ticks intersected to form a grid across the plot.