Skip to content

Adding colorbar changes imshow plot color when vmin is close to vmax #5467

Closed as not planned
@IamJeffG

Description

@IamJeffG

I can't tell whether this is an intended feature or a bug, so I'm going to run it by the group.

f = plt.figure()
mappable = plt.gca().imshow([[42]])

Here, we gave a single pixel, so the entire plot is the same color.
With default jet colormap, that single color is dark blue (the bottom of the jet cmap). So far so good.

f.colorbar(mappable)

Here, observe that since vmin==vmax (effectively), the colorbar defaulted to the midpoint of the colormap, now green. Luckily, the Axes from imshow, containing the data, changed too!

On one hand, I like that the colorbar shows context around the singular value. (I think due to this line.) On the other hand, over in Geopandas we plot patches one-by-one with face_color values from a normalized colormap, but adding this renormalization means the colorbar no longer matches the cmap I passed it.

Thoughts? If you tell me this is intended I'm willing to find a workaround to my use case. (Frankly I'm not 100% sure what I would expect matplotlib to do here instead.) Just wanted to get a second opinion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions