我正在使用 matplotlib 在 python 中绘图。默认设置是:
plt.ticklabel_format(style='sci')
@Ffisegydd的答案对于我来说仍然适用于 python 3.11.7。他使用
import matplotlib.ticker as mtick
和 ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.2e'))
。将 .2e
替换为您喜欢的任何内容(请参阅格式文档)。这会给你这样的东西
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
x = np.linspace(0,1,1000)
y = np.linspace(0,1e6,1000)
fig = plt.figure(clear='True')
ax = fig.add_subplot(111)
ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.2e'))
ax.plot(x,y)