python - 删除 matplotlib 图中的 xticks?

标签 python matplotlib plot

我有一个 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()

enter image description here

关于python - 删除 matplotlib 图中的 xticks?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12998430/

相关文章:

python - 在 for 循环中创建一个新的顺序模型(使用 Keras)

python - 将 View 与模板 View django 合并

python - 已弃用警告 - mataplotlib 库中的 where 参数

python - matplotlib 轮廓 : get Z value under cursor

python - 使用 python 读取 .dat 文件

python - 如何结合两个 pd 数据框,根据分数重新排名并返回整行以获得最高排名?

python Pandas : diff between 2 dates in a groupby

python - 按小时将日期时间对象排序为 Pandas 数据框,然后使用 Matplotlib 可视化为直方图

python - matplotlib Legend 中的 Latex 引用

python - 绘制动画时间