当我试图绘制这些数据时,我在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
]
结果是,注意指数:
我怎样才能摆脱这个?
最佳答案
它是matplotlib术语,称为偏移量,而不是指数。(以便于将来进行搜索。)
默认情况下,matplotlib假设您希望尽可能紧凑地显示数据范围,因此它将包括偏移量和/或乘数,以使显示更加紧凑(请注意-
而不是x
)。
如果您不希望您的绘图以这种方式显示,删除它的最简单方法是使用plt.ticklabel_format(useOffset=False)
(您必须忽略camelcase)。
举个简单的例子:
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()