如何在 Matplotlib 中更改科学计数法的字体大小?


若要更改 matplotlib 中科学计数法的字号,我们可以采取以下步骤——

  • 设置图形的大小,并调整子图之间的边距。

  • 列出 x 和 y 的值。

  • 使用 plot() 方法绘制 x 和 y 数据点。

  • 若要更改科学计数法的字号,我们可以使用样式名 style="sci"

  • 若要显示图形,请使用 show() 方法。

示例

from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

x = [10000, 20000, 300000, 34, 1, 10000]
y = [1, 2, 0, 4, 1, 5]

plt.plot(x, y, color='red')
plt.ticklabel_format(axis="x", style="sci", scilimits=(0, 0))

plt.show()

输出

更新于: 2021 年 6 月 3 日

2K+ 次查看

开启你的 职业生涯

完成课程以获得认证

开始
广告
© . All rights reserved.