This is because you're sharing the same locator object between multiple y-axis objects.
It's not a bug, but it is a subtle issue that can cause a lot of confusion. The documentation could probably be more clear about this, but locators are expected to belong to a single axis
.
You actually can share the same Formatter
instance, but it's probably better not to, unless you're aware of the ramifications (changes to one will affect all).
Instead of recycling the same Locator
and Formatter
instances, create new ones for each axis:
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
fig, axes = plt.subplots(2, 2)
for ax in axes.flat:
ax.yaxis.set(major_locator=MultipleLocator(0.1),
major_formatter=FormatStrFormatter('%2.1f'))
ax.set_ylim(0, 1)
axes[-1, -1].set_ylim(1, 2)
plt.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…