gpt4 book ai didi

python /matplotlib : imposed ticks with ticker partially missing

转载 作者:太空宇宙 更新时间:2023-11-03 16:03:21 24 4
gpt4 key购买 nike

当用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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com