python - 绘制窄范围数据的奇数指数

标签 python matplotlib ipython

在尝试绘制此数据时,我在 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
]

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

Graph with odd exponent

我怎样才能摆脱这个?

最佳答案

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

enter image description here

关于python - 绘制窄范围数据的奇数指数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16509710/

相关文章:

python - tf.placeholder_with_default 反向传播

python - 在 IPython 的子进程中使用 input() 以 %%script py -2 开始

python - ipython 自动重载不起作用

python - Python 中非常大的 bool 列表

python - 在 Python 中替换字符串系列中不正确单词的有效方法

python - 无法加入标记

python - 带圆形单位的 Matplotlib imshow

python - IPython 笔记本 : How to combine HTML output and matplotlib figures?

python - 解码 json 并遍历 django 模板中的项目

python - WxPython 问题 : Subpanels within a Notebook Panel