删除matplotlib图中的xticks?
发布于 2021-01-29 15:00:10
我有一个Semilogx图,我想删除xticks。我试过了:
plt.gca().set_xticks([])
plt.xticks([])
ax.set_xticks([])
网格消失(确定),但仍保留小刻度线(在主刻度线的位置)。如何删除它们?
关注者
0
被浏览
131
1 个回答
-
该
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()