Search code examples
pythonaxis-labels

Python - Remove axis tick labels, keeping ticks and axis label


I would like to remove the numerical values in each thick of my y-axis (10, 20, 30, etc.) but keeping the thick marks and the axis label. So far I just have:

yticks([])

but it removes the ticks as well. I also tried:

frame=gca()
frame.axes.get_yaxis().set_visible(False)

but it removes both axis label and axis ticks.


Solution

  • You can set the tick labels to an empty list:

    from matplotlib.pyplot import *
    gca().set_xticklabels(['']*10)
    plot(range(10))
    

    Results in enter image description here

    I had to do that before I called plot. Not sure why the other way around didn't work