Description
Bug summary
Setting y ticks and labels directly on an axis and then adjusting the top of the subplot of the figure can have unexpected consequences. Depending on where those ticks and labels were originally, and how the top
ratio is set, labels will not go until the top of the y-axis, instead all the values appear with much less vertical spacing on the bottom part of the axis.
Code for reproduction
import matplotlib.pyplot as plt
from mpl_toolkits.axisartist import SubplotHost
fig = plt.figure(figsize=(25, 3)) # Originally setting a large enough height fixed our problem, but in this example it did not help
ax = SubplotHost(fig, 111)
fig.add_subplot(ax)
# ax = fig.add_subplot(111) # using this produces the same outcome
data = [33.4, 33.5, 33.6]
ax.plot(data, data)
ticks = [32.8, 33., 33.2, 33.4, 33.6, 33.8]
# Anomaly because labels won't match with ticks anymore if the next line is commented out
# ax.set_yticks(ticks)
ax.set_yticklabels(map(str, ticks))
# In this little example the bug is only triggered when the anomaly above holds
fig.subplots_adjust(top=0.96)
plt.show(dpi=300)
Actual outcome
Expected outcome
Additional information
I suspect it depends on where those ticks and labels were originally, because we were also able to produce this bug where there was no mismatch required between labels and ticks.
It might also depend on the number of the top ratio being set.
As far as I know, adjusting other ratios (left, right, bottom, wspace, hspace) did not have an effect on this.
Operating system
Ubuntu 22.04
Matplotlib Version
3.5.1
Matplotlib Backend
agg
Python version
3.9.12
Jupyter version
No response
Installation
pip