【问题标题】:How to force matplotlib to use exponent notation in Y axis?如何强制 matplotlib 在 Y 轴上使用指数符号?
【发布时间】:2019-10-03 12:37:41
【问题描述】:

当使用 plt.plot 系列以非常小的数字进行绘图时,它看起来像这样。

只有当数字非常小时(大约 1E-7),它才会变为指数符号:

有没有办法强制 matplotlib 切换到更大数字的指数符号?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    你想要Axes.ticklabel_format()。试试这个,例如:

    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.arange(100)
    y = np.random.random(100) * 1e5
    
    fig, ax = plt.subplots()
    ax.plot(x, y)
    ax.ticklabel_format(axis='y', scilimits=[-3, 3])
    plt.show()
    

    这会导致:

    来自文档:

    sclimits — (m, n),整数对;如果 style 是 'sci',科学记数法将用于 10m 到 10n 范围之外的数字。使用 (0,0) 包括所有数字。使用 (m,m) where m 0 将数量级固定为 10m。

    【讨论】:

      猜你喜欢
      • 2012-08-16
      • 2015-02-14
      • 2020-10-17
      • 2014-02-19
      • 1970-01-01
      • 1970-01-01
      • 2012-12-19
      • 1970-01-01
      • 2020-05-12
      相关资源
      最近更新 更多