Closed
Description
Bug summary
Adding a title to a colorbar works fine in most cases, but misplaces the title text when using extend=max
as argument to plt.colorbar()
.
Code for reproduction
fig, ax = plt.subplots(figsize=(6,6))
x, y, z = [np.random.random(100) for i in range(3)]
scatter = ax.scatter(x, y, c=z)
cbar = plt.colorbar(scatter, extend="max", ax=ax)
cbar.ax.set_title("asdf")
Actual outcome
Expected outcome
I would expect the title text to be above the colorbar including the arrow. This is what happens when running the above code but without extend="max"
:
fig, ax = plt.subplots(figsize=(6,6))
x, y, z = [np.random.random(100) for i in range(3)]
scatter = ax.scatter(x, y, c=z)
cbar = plt.colorbar(scatter, ax=ax)
cbar.ax.set_title("asdf")
Additional information
Aesthetically, this is less of an issue with smaller figure sizes but it should generally place the text in the right place irrespective of figure dimensions.
Operating system
No response
Matplotlib Version
3.5.1
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
No response