Matplotlib 显示错误的 y 轴值

Ant*_*tys 3 python matplotlib python-3.x

我的代码很简单:

values = [-2071238, -2071241, -2071240, -2071242, -2071244, -2071239, -2071221, -2071194, -2071224, -2071240, -2071244, -2071241, -2071240, -2071241, -2071237, -2071223, -2071205, -2071225, -2071238]
indx = [0.0, 20.0, 40.0, 60.0, 80.0, 100.0, 120.0, 140.0, 160.0, 180.0, 200.0, 220.0, 240.0, 260.0, 280.0, 300.0, 320.0, 340.0, 360.0]

plt.scatter(indx, values)

#rendering
plt.xlabel("Axis 1")
plt.ylabel("Axis 2")
title = "All"
plt.title(title)
plt.savefig(title + ".png")
plt.show()
Run Code Online (Sandbox Code Playgroud)

然而,结果图如下:

图片

显然每个点都没有好的 y 值。

我做错了什么或者忘记了什么吗?

mac*_*nic 5

你的图在 y 轴上确实有很好的值,但它们有一个偏移。可以禁用偏移:

import matplotlib.pyplot as plt

values = [-2071238, -2071241, -2071240, -2071242, -2071244, -2071239, -2071221, -2071194, -2071224, -2071240, -2071244, -2071241, -2071240, -2071241, -2071237, -2071223, -2071205, -2071225, -2071238]
indx = [0.0, 20.0, 40.0, 60.0, 80.0, 100.0, 120.0, 140.0, 160.0, 180.0, 200.0, 220.0, 240.0, 260.0, 280.0, 300.0, 320.0, 340.0, 360.0]

plt.scatter(indx, values)

# disabling the offset on y axis
ax = plt.gca()
ax.ticklabel_format(useOffset=False)

#rendering
plt.xlabel("Axis 1")
plt.ylabel("Axis 2")
title = "All"
plt.title(title)
plt.savefig(title + ".png")

plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述