Pythonice
Pythonice

Reputation: 333

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.

Upvotes: 3

Views: 19163

Answers (4)

Leosdo
Leosdo

Reputation: 11

Another simple solution is:

ax.set_xticklabels([])

Upvotes: 1

user3602939
user3602939

Reputation: 61

I agree with Mathieu that tick_params() is a better method (because you don't need to know the number of ticks in advance), however the most generalized parameter is "label1On," i.e.:

gca().tick_params(axis='x',label1On=False)

This approach easily extends to 'y' axis, as well as the second 'x' or 'y' axes (using label2On).

Upvotes: 3

Mathieu Perrin
Mathieu Perrin

Reputation: 31

The tick_params() function should do the job:

gca().tick_params(axis='x',labelbottom='off')

Upvotes: 3

mbatchkarov
mbatchkarov

Reputation: 16119

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

Upvotes: 1

Related Questions