Matplotlib的自动缩放在小值的y轴上似乎不起作用?

2024-05-16 14:39:05 发布

您现在位置:Python中文网/ 问答频道 /正文

因为某种原因,自动缩放对于非常小的值(如1E-05)似乎不起作用。如图所示,所有内容都显示在靠近零轴的位置。在

你知道我哪里出错了吗?在

import matplotlib.pyplot as plt

y=  [1.09E-05,  1.63E-05,   2.45E-05,   3.59E-05,   5.09E-05,   6.93E-05,   9.07E-05]
x=  [0, 10, 20, 30, 40, 50, 60]

fig3, ax3 = plt.subplots()
ax3.scatter(x, y, color='k', marker = "o")
ax3 = plt.gca()
plt.autoscale(enable=True, axis="y", tight=False)
plt.show()

enter image description here


Tags: import内容matplotlibenableaspltmarkercolor
1条回答
网友
1楼 · 发布于 2024-05-16 14:39:05

我相信这是a known issue,它仍然没有在matplotlib中解决。它与herehere相同。在

可能的解决方案是

使用plot而不是scatter。在

import matplotlib.pyplot as plt

y=  [1.09E-05,  1.63E-05,   2.45E-05,   3.59E-05,   5.09E-05,   6.93E-05,   9.07E-05]
x=  [0, 10, 20, 30, 40, 50, 60]

fig3, ax3 = plt.subplots()
ax3.plot(x, y, color='k', marker = "o", ls="")
ax3.autoscale(enable=True, axis="y", tight=False)
plt.show()

除了scatter之外,还使用不可见的plot

^{pr2}$

使用set_ylim手动缩放轴。在

import matplotlib.pyplot as plt

y=  [1.09E-05,  1.63E-05,   2.45E-05,   3.59E-05,   5.09E-05,   6.93E-05,   9.07E-05]
x=  [0, 10, 20, 30, 40, 50, 60]

fig3, ax3 = plt.subplots()
ax3.scatter(x, y, color='k', marker = "o")

dy = (max(y) - min(y))*0.1
ax3.set_ylim(min(y)-dy, max(y)+dy)
plt.show()

相关问题 更多 >