gpt4 book ai didi

python - 默认情况下,Python 绘图使用科学记数法

转载 作者:行者123 更新时间:2023-12-01 09:18:12 25 4
gpt4 key购买 nike

简单的问题:如何让 Python 在绘图中默认使用科学记数法?从各种帖子中我可以写一些类似的东西

from numpy import linspace
import matplotlib.pyplot as plt

plt.figure()
plt.plot(linspace(1e6,2e6),linspace(1e6,1e7))

plt.figure()
plt.plot(linspace(8e6,9e6),linspace(2e6,2.5e7))

plt.ticklabel_format(style='sci', axis='both', scilimits=(-2,2))
plt.show()

但是ticklabel_format仅作用于matplotlib生成的最后一个图。 (如果将 plt.ticklabel_format() 放在代码的开头,我还会得到一个显示 x、y 轴的空白图。)

最佳答案

您可以通过编辑“rc”文件来修改 matplotlib 的默认行为。请参阅Customizing matplotlib .

就您而言,您似乎可以调整该项目:

axes.formatter.limits : -2, 2 # use scientific notation if log10
# of the axis range is smaller than the
# first or larger than the second

关于python - 默认情况下,Python 绘图使用科学记数法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51040027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com