我尝试使用(https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.ticklabel_format.html)中描述的Axes.ticklabel_format函数将matplotlib绘图轴标签的格式更改为科学格式。使用以下玩具代码
import numpy as np
import matplotlib.pyplot as plt
# Data...
T = np.arange(0, 101, 0.01)
R_e = 1.68799673810490
R = np.sin(T) + R_e
# Plotting figure
fig, ax = plt.subplots(1, 1)
ax.plot(T, R)
# Attempting to set scientific format for both axes
ax.ticklabel_format(axis = 'both', style = 'scientific', scilimits = (0, 0))
# Save figure
plt.savefig('Test.png', format = 'png')
您可以手动或使用
matplotlib.ticker
: 设置这样的偏移量
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
T = np.arange(0, 101, 0.01)
R_e = 1.68799673810490
R = np.sin(T) + R_e
fig, ax = plt.subplots(1, 1)
ax.plot(T, R)
formatter = ticker.ScalarFormatter(useOffset=True, useMathText=True)
formatter.set_scientific(True)
formatter.set_powerlimits((1, 1)) # defines when to apply scientific notation
ax.xaxis.set_major_formatter(formatter)
ax.yaxis.set_major_formatter(formatter)
plt.show()