标准形式 matplotlib -- 将 e 更改为 \times 10 [英] standard form matplotlib -- change e to \times 10
问题描述
在 matplotlib 中,轴有时以标准形式显示.数字由刻度显示,轴上出现类似1e-7"的内容.有没有办法将其更改为写出的$ \ times 10 ^ {-7} $?
In matplotlib, the axes are sometimes displayed in standard form. The numbers are shown by the ticks and something like '1e-7' appears by the axis. Is there a way to change that to a written out $\times 10^{-7}$?
我不想更改每个刻度上的标签.我希望更改出现在轴底部的文字1e-7".
I am not looking to change the labels on each individual tick. I am looking to change the text that appears once at the bottom of the axis saying '1e-7'.
推荐答案
最简单的答案:使用乳胶模式:
The simplest answer: Use the latex mode:
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['text.usetex'] = True
x = np.arange(10000, 10011)
plt.plot(x)
plt.show()
结果:
编辑:
实际上,您根本不需要使用乳胶.默认使用的 ScalarFormatter
可以选择使用科学计数法:
Actually you don't need to use latex at all. The ScalarFormatter
which is used by default has an option to use scientific notation:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
x = np.arange(10000, 10011)
fig, ax = plt.subplots(1)
ax.plot(x)
formatter = mticker.ScalarFormatter(useMathText=True)
ax.yaxis.set_major_formatter(formatter)
plt.show()
结果:
这篇关于标准形式 matplotlib -- 将 e 更改为 \times 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!