3

尝试绘制此数据时,我在 ipython 笔记本中得到 matplotlib 的一些非常奇怪的行为:

[
    -142.8916729, -142.89161936, -142.89161954, -142.89162066,
    -142.89162031, -142.89162033, -142.89162049, -142.89162055,
    -142.89162054, -142.89162084, -142.89162155, -142.89162204,
    -142.89162172, -142.89162157, -142.89162164, -142.89162162,
    -142.89162163, -142.89162165, -142.89162166, -142.89162166,
    -142.89162166, -142.89162167, -142.89162167, -142.89162167,
    -142.89162167, -142.89162167, -142.89162167, -142.89162167,
    -142.89162167, -142.89162167, -142.89162167, -142.89162167,
    -142.89162152
]

结果是这样的,注意指数:

奇数指数图

我怎样才能摆脱这个?

4

1 回答 1

4

它用matplotlib术语,它被称为偏移量,而不是指数。(为了将来更容易搜索。)

默认情况下,matplotlib 假定您希望尽可能紧凑地显示数据范围,因此它将包含偏移量和/或乘数以使显示更加紧凑(注意用.-代替x.)

如果您不希望以这种方式显示您的情节,删除它的最简单方法是使用plt.ticklabel_format(useOffset=False)(您必须忽略骆驼案。)

举个简单的例子:

import matplotlib.pyplot as plt
import numpy as np

x = np.array([-142.8916729, -142.89161936, -142.89161954, -142.89162066,
              -142.89162031, -142.89162033, -142.89162049, -142.89162055,
              -142.89162054, -142.89162084, -142.89162155, -142.89162204,
              -142.89162172, -142.89162157, -142.89162164, -142.89162162,
              -142.89162163, -142.89162165, -142.89162166, -142.89162166,
              -142.89162166, -142.89162167, -142.89162167, -142.89162167,
              -142.89162167, -142.89162167, -142.89162167, -142.89162167,
              -142.89162167, -142.89162167, -142.89162167, -142.89162167,
              -142.89162152])
fig, ax = plt.subplots()
ax.plot(x)
ax.ticklabel_format(useOffset=False)
plt.show()

在此处输入图像描述

于 2013-05-12T16:52:42.817 回答