matplotlib 使用绝对值而不是偏移值显示y轴范围

fnx2tebb  于 2023-06-06  发布在  其他
关注(0)|答案(3)|浏览(435)

我有以下范围的numpy数据(usec时间戳的增量):

array([ 4.312,  4.317,  4.316,  4.32 ,  4.316,  4.316,  4.319,  4.317,
    4.317,  4.316,  4.318,  4.316,  4.318,  4.316,  4.318,  4.317,
    4.317,  4.317,  4.316,  4.317,  4.318,  4.316,  4.318,  4.316,
    4.318,  4.316,  4.317,  4.317,  4.318,  4.316,  4.317,  4.317,
    4.317,  4.317,  4.317,  4.316,  4.319,  4.315,  4.319,  4.315,
    4.319,  4.315,  4.316,  4.319,  4.317,  4.317,  4.317,  4.318,
    4.315,  4.317,  4.317,  4.317,  4.319,  4.314,  4.32 ,  4.315,
    4.317,  4.318,  4.315,  4.318,  4.317,  4.317,  4.317,  4.316,
    4.317,  4.318,  4.317,  4.317,  4.317,  4.315,  4.319,  4.317,
    4.315,  4.319,  4.316,  4.318,  4.318,  4.315,  4.318,  4.317,
    4.317,  4.321])

当我使用matplotlib.pyplot绘图时:

import matplotlib.pyplot as plt
 plt.plot( deltas ) 
 plt.show()

我得到了下面的情节。为什么Y轴以这种方式缩放?如何将Y轴标记为数据,而不是数据的偏移?有时图是“+4.nnn”,有时不是(取决于数据范围?).
“奇怪地”策划:

“正确”绘制:

wvyml7n5

wvyml7n51#

将useOffset设置为False:

ax = plt.gca()
ax.ticklabel_format(useOffset=False)
qacovj5a

qacovj5a2#

This answer建议禁用偏移量作为全局设置,这对我很有效:

matplotlib.rcParams['axes.formatter.useoffset'] = False
qni6mghb

qni6mghb3#

您还可以使用

ax = plt.gca()
ax.set_yticklabels(ax.get_yticks())

不过我还是更喜欢@HYRY的回答。

相关问题