python /matplotlib : imposed ticks with ticker partially missing

标签 python matplotlib ticker

当用plt.axis('auto')绘制我的图形时,“自然”x-ticks以频率500写入,

enter image description here

希望频率200,我用过:

    import matplotlib.ticker as ticker

    ticks_loc = ticker.MultipleLocator(base=200)

    fig = plt.figure('Cutlines x-axis')
    ax = fig.add_subplot(111)
    ...
    plt.axis('equal')
    ax.xaxis.set_major_locator(ticks_loc)
    ax.yaxis.set_major_locator(ticks_loc)
    plt.grid()

这给出了,

enter image description here

奇怪的是

  1. 所有刻度均未表示(刻度 -1000、-800、-600 缺失)
  2. plt.show()savefig 不同(在 plt.show() 中“仅”缺少刻度 -1000 和 -800 ,不是-600)。

我尝试过减小字体大小(非常小)和/或垂直书写 -> 没有效果:总是缺少相同的刻度。

有没有办法让所有刻度都可见(在水平模式下)?

最佳答案

为什么不简单地使用xticks而不是ticker

fig = plt.figure('Cutlines x-axis')
ax = fig.add_subplot(111)
...
xlim = ax.get_xlim()
plt.xticks(np.arange(xlim[0], xlim[1]+200, 200))

关于 python /matplotlib : imposed ticks with ticker partially missing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40088157/

相关文章:

python - 将一个 DataFrame 行转换为平面列表

python - 在 python 虚拟环境中使用 pip 安装 Pandas 时出现“bz2 模块不可用”

facebook - 如何在 Facebook 上发布内容,就像 Spotify 对音乐所做的那样

python - 关于在不覆盖现有数据的情况下将此数据(JSON)存储在 Redis 中的建议?

python - Pandas:[Errno 75] 值对于定义的数据类型来说太大

python - 在 Python 的 matplotlib 中绘制球体表面的点

python - matplotlib 中 Windrose 的子图

python - 如何暂停/恢复 matplotlib 艺术家动画

javascript - 在 jQuery 中连续滚动包含图像的水平滚动条?

jquery - 动画循环显示列表项