我有一个 semilogx 图,我想删除 xticks。我试过了:
plt.gca().set_xticks([])
plt.xticks([])
ax.set_xticks([])
网格消失(好的),但小刻度(在主要刻度的位置)仍然存在。如何删除它们?
最佳答案
plt.tick_params
方法对于这样的东西非常有用。此代码关闭主要和次要刻度并从 x 轴上删除标签。
注意还有ax.tick_params
对于 matplotlib.axes.Axes
对象。
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()
关于python - 删除 matplotlib 图中的 xticks?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12998430/