SI 前缀偏移量与自然数量级#

matplotlib.ticker.EngFormatter 能够为您的轴数据计算自然偏移量,并使用自动计算的标准 SI 前缀进行显示。

下面是此类图表的一个示例

engformatter offset
import matplotlib.pyplot as plt
import numpy as np

import matplotlib.ticker as mticker

# Fixing random state for reproducibility
np.random.seed(19680801)

UNIT = "Hz"

fig, ax = plt.subplots()
ax.yaxis.set_major_formatter(mticker.EngFormatter(
    useOffset=True,
    unit=UNIT
))
size = 100
measurement = np.full(size, 1e9)
noise = np.random.uniform(low=-2e3, high=2e3, size=size)
ax.plot(measurement + noise)
plt.show()

由 Sphinx-Gallery 生成的画廊