簡體   English   中英

Matplotlib 顯示錯誤的 y 軸值

[英]Matplotlib showing wrong y-axis values

我的代碼很簡單:

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()

但是,結果圖如下:

圖片

這顯然沒有每個點的良好 y 值。

我做錯了什么或忘記了什么?

你的圖在 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()

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM