Python Matplotlib 2.x Axis Autolimit
Solution 1:
First, note that the number of ticks on the axes is different between the classic mode and the adapted rcParams.
import matplotlib.pyplot as plt
mode = "classic"#"classic" #"modern"if mode == "classic":
plt.style.use('classic')
else:
plt.rcParams['axes.autolimit_mode'] = 'round_numbers'
plt.rcParams['axes.xmargin'] = 0
plt.rcParams['axes.ymargin'] = 0
z = [49.0, 14.5, 6.0, 5.8]
plt.figure(figsize=(3,6))
plt.subplot(311)
plt.title("{} mode".format(mode))
plt.plot(range(len(z)), z)
Because of that different number of ticks, also the next "round number" is different. In classic mode it is 5 and 50, in "modern" mode 0 and 60.
The changes to the defaults guide states in the "number of ticks" section:
The locator now includes an algorithm to estimate the maximum number of ticks that will leave room for the tick labels. [...] There is no way, other than using
mpl.style.use('classic'), to restore the previous behavior as the default. [...] The algorithm used byMaxNLocatorhas been improved, and this may change the choice of tick locations in some cases. This also affectsAutoLocator, which usesMaxNLocatorinternally.
Here, you have run into exactly one of those "in some cases".


Post a Comment for "Python Matplotlib 2.x Axis Autolimit"