从 matplotlib 3.1 开始,您可以通过以下方式轻松定义任何自定义比例
ax.set_yscale('function', functions=(forward, inverse))
另请参阅https://matplotlib.org/3.1.1/gallery/scales/scales.html https://matplotlib.org/3.1.1/gallery/scales/scales.html
在这种情况下,例如:
from functools import partial
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(1, 40, 100)
y = np.linspace(1, 4, 100)
fig, ax = plt.subplots()
ax.plot(x, y)
# Set y scale to exponential
ax.set_yscale('function', functions=(partial(np.power, 10.0), np.log10))
ax.set(xlim=(1,40), ylim=(1,4))
ax.set_yticks([1, 3, 3.5, 3.75, 4.0])
plt.show()