您可以固定要在轴上显示的数量级,如下所示这个问题 https://stackoverflow.com/questions/42656139/set-scientific-notation-with-fixed-exponent-and-significant-digits-for-multiple。这个想法是对通常的子类进行分类ScalarFormatter
并固定要显示的数量级。然后设置useOffset
设置为 False 将防止显示一些偏移,但仍显示该系数。
格式"%1.1f"
将仅显示一位小数。最后使用一个MaxNLocator
允许设置轴上的最大刻度数。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker
class OOMFormatter(matplotlib.ticker.ScalarFormatter):
def __init__(self, order=0, fformat="%1.1f", offset=False, mathText=True):
self.oom = order
self.fformat = fformat
matplotlib.ticker.ScalarFormatter.__init__(self,useOffset=offset,useMathText=mathText)
def _set_orderOfMagnitude(self, nothing):
self.orderOfMagnitude = self.oom
def _set_format(self, vmin, vmax):
self.format = self.fformat
if self._useMathText:
self.format = '$%s$' % self.format
x = [0.6e-8+14.41249698, 3.4e-8+14.41249698]
y = [-7.7e-11-1.110934954e-2, -0.8e-11-1.110934954e-2]
fig, ax = plt.subplots()
ax.plot(x,y)
y_formatter = OOMFormatter(-2, "%1.1f")
ax.yaxis.set_major_formatter(y_formatter)
x_formatter = OOMFormatter(1, "%1.1f")
ax.xaxis.set_major_formatter(x_formatter)
ax.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(2))
ax.yaxis.set_major_locator(matplotlib.ticker.MaxNLocator(2))
plt.show()
请记住,这个图是不准确的,您不应该在交给其他人的任何类型的报告中使用它,因为他们不知道如何解释它。