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

南笙酒味 提交于 2020-01-05 12:34:07

问题


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.


回答1:


You can set the tick labels to an empty list:

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

Results in

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




回答2:


The tick_params() function should do the job:

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


来源:https://stackoverflow.com/questions/24520244/python-remove-axis-tick-labels-keeping-ticks-and-axis-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!