我有一个semilogx情节,我想删除xticks。我试过了:
plt.gca().set_xticks([])
plt.xticks([])
ax.set_xticks([])
网格消失(确定),但小蜱(在主蜱的位置)仍然存在。如何删除它们?
tick_params
方法对于这样的东西非常有用。此代码关闭主要和次要刻度,并从x轴中删除标签。
from matplotlib import pyplot as plt
plt.plot(range(10))
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom=False, # ticks along the bottom edge are off
top=False, # ticks along the top edge are off
labelbottom=False) # labels along the bottom edge are off
plt.show()
plt.savefig('plot')
plt.clf()
不完全是OP所要求的,但是禁用所有轴线,刻度线和标签的简单方法是简单地调用:
plt.axis('off')
这是我在matplotlib mailing list上找到的替代解决方案:
import matplotlib.pylab as plt
x = range(1000)
ax = plt.axes()
ax.semilogx(x, x)
ax.xaxis.set_ticks_position('none')
或者,您可以传递空的刻度位置并标记为
plt.xticks([], [])
有一个比John Vinyard给出的更好,更简单的解决方案。使用NullLocator
:
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.show()
plt.savefig('plot')
希望有所帮助。
试试这个去除标签(但不是刻度线):
import matplotlib.pyplot as plt
plt.setp( ax.get_xticklabels(), visible=False)
此代码段可能有助于仅删除xticks。
from matplotlib import pyplot as plt
plt.xticks([])
这段代码可能有助于删除xticks和yticks。
from matplotlib import pyplot as plt
plt.xticks([]),plt.yticks([])
# remove all the ticks (both axes), and tick labels on the Y axis
plt.tick_params(top='off', bottom='off', left='off', right='off', labelleft='off', labelbottom='on')