Skip to content

using AxesImage.set_clim() shrinks the colorbar #12682

Description

@DizietAsahi

Bug report

Bug summary
I am puzzled by the following behavior. Is this intended or a bug?

After creating a colorbar, if setting the limits of the color range with a shorter range of vmin,vmax results in a shrunken colorbar

Code for reproduction

fig, ax = plt.subplots()
data = np.random.random(size=(50,50))
img = ax.imshow(data)
cb = plt.colorbar(img)
# the colorbar is the same height as the plot at this point
#img.set_clim([0.25,0.75])  # running this line will produce a shrunken colorbar
#img.set_clim([-0.25,1.25])  # running this line will change the limits of the colorbar
                             # and return the colorbar to its original size

Actual outcome

This is the result of a small animation where vmax is increased from 0.5 to 1.5 then back

test

Expected outcome

I was expecting the colorbar to stay the same size, and only the tick range to change. Certainly the colorbar does not grow when setting a larger range of vmin,vmax but shrinks when using a smaller range, which seems inconsistent.

Matplotlib version

  • Operating system: osx
  • Matplotlib version: 3.0.0
  • Matplotlib backend (print(matplotlib.get_backend())): nbAgg
  • Python version: Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:07:29)
  • Jupyter version (if applicable):The version of the notebook server is: 5.7.0
  • Other libraries:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions