Warm tip: This article is reproduced from serverfault.com, please click

Python hide ticks but show tick labels

发布于 2015-05-01 13:58:01

I can remove the ticks with

ax.set_xticks([]) 
ax.set_yticks([]) 

but this removes the labels as well. Any way I can plot the tick labels but not the ticks and the spine

Questioner
user308827
Viewed
44
Julien Spronck 2015-05-01 22:14:08

You can set the tick length to 0 using tick_params (http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.tick_params):

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1],[1])
ax.tick_params(axis=u'both', which=u'both',length=0)
plt.show()