Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Colormap + NoNorm only plots one color under matplotlib 3.5.0 #21870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dominiquesydow opened this issue Dec 5, 2021 · 2 comments · Fixed by #21872
Closed

[Bug]: Colormap + NoNorm only plots one color under matplotlib 3.5.0 #21870

dominiquesydow opened this issue Dec 5, 2021 · 2 comments · Fixed by #21872

Comments

@dominiquesydow
Copy link

Bug summary

My aim is to plot a colormap with e.g. 5 discrete colors (with 5 ticks centered per color).

Under matplotlib 3.4.3, I got this working with the code snippet below using NoNorm; under 3.5.0, only one color is plotted.

Is this a bug - or is my setup incorrect/unidiomatic and worked only by chance before?

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib import cm, colors

data = [1, 2, 3, 4, 5]

fig, ax = plt.subplots(figsize=(6, 1))
fig.subplots_adjust(bottom=0.5)

norm = colors.NoNorm(vmin=min(data), vmax=max(data))
cmap = cm.get_cmap("viridis", len(data))
cbar = fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), cax=ax, orientation="horizontal")
print(cbar.get_ticks())

Actual outcome

image

This is the output under matplotlib 3.5.0.

Expected outcome

image

This was the output under matplotlib 3.4.3.

Additional information

No response

Operating system

Ubuntu

Matplotlib Version

3.5.0

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.9.7

Jupyter version

3.2.4

Installation

conda

@tacaswell
Copy link
Member

tacaswell commented Dec 6, 2021

This definitely is a regression, sorry about that.

This bisects back to 146856b / #20054 which is part of an on going effort to make the colorbar code "less special" and hence easier to maintain and work with, unfortunately it looks like then special path for handling NoNorm (which is when compared to our other norms quite special as its output domain is what ever you put in rather than [0, 1]) did not make it across quite right.

I'll see if I can make any progress on sorting this out, but this may need attention from @jklymak.

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Dec 6, 2021
Closes matplotlib#21870

This adds another special-case path for NoNorm and tweaks the contents of another.
These special-cases are required because NoNorm (like BoundaryNorm) has a
different return value than ever other Norm (it directly returns integers to
index into the LUT rather than [0, 1] that is later mapped into the LUT.
@jklymak
Copy link
Member

jklymak commented Dec 6, 2021

Yes, sorry we broke this. Some of colorbars' features were completely untested, so we are finding lots of things dropped in 3.5.0. We will try and have all reported ones squashed by 3.5.1....

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Dec 6, 2021
Closes matplotlib#21870

This adds another special-case path for NoNorm and tweaks the contents of another.
These special-cases are required because NoNorm (like BoundaryNorm) has a
different return value than ever other Norm (it directly returns integers to
index into the LUT rather than [0, 1] that is later mapped into the LUT.

Co-authored-by: Jody Klymak <[email protected]>
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Dec 6, 2021
Closes matplotlib#21870

This adds another special-case path for NoNorm and tweaks the contents of another.
These special-cases are required because NoNorm (like BoundaryNorm) has a
different return value than ever other Norm (it directly returns integers to
index into the LUT rather than [0, 1] that is later mapped into the LUT.

Co-authored-by: Jody Klymak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants