-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[MNT]: ListedColormap inconsistencies #28763
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
Comments
There is also an odd behavior that if you pass a non-iterable as
|
Let's deprecate scalar/string argument. I don't expect is is widely used, and |
Does that mean that we should deprecate the N argument as well? As |
I believe N can go as well. Truncating colors by the user is simple. Repeating a short list multiple times should be the very exception (and should possibly have required explicit user consent as duplicate colors make the mapping ambiguous). |
Primary motivation was to remove the N parameter to ListedColormap (in preparation of its deprecation matplotlib#28763 (comment) -2322791660). That parameter is not needed here because `len(colors[color_slice]) == n_data_colors)`, otherwise the ValueError above would have raised. Hopefully, this is overall more readable.
Primary motivation was to remove the N parameter to ListedColormap (in preparation of its deprecation matplotlib#28763 (comment) -2322791660). That parameter is not needed here because `len(colors[color_slice]) == n_data_colors)`, otherwise the ValueError above would have raised. Hopefully, this is overall more readable.
The parameter N is deprecated in #29135. When the deprecation expires, N will be gone, which resolves this issue. I'm closing as there are no further actions needed. The deprecation will guide people away from the API in question. And when expiring the topic is done. |
Summary
The documentation to
ListedColormap
states that the input should be a list or arraymatplotlib/lib/matplotlib/colors.py
Lines 1175 to 1177 in b01462c
However, when specifying N,
str
andfloat
are also supported (if one use the source code)matplotlib/lib/matplotlib/colors.py
Lines 1199 to 1214 in b01462c
This means that, e.g.,
ListedColormap("#aabbcc", N=1)
works, butListedColormap("#aabbcc")
does not (there will be weird errors later, likeN=7
for the latter). Given that there ismonochrome
attribute and the documentation of N, one may expect the latter to work as well (if the earlier works). Also,ListedColormap(["#aabbcc"])
will not set themonochrome
attribute correctly.Proposed fix
I think there are three(?) possible solutions:
ListedColormap(0.3, N=7)
thanListedColormap([0.3]*7)
or at least require slightly less Python knowledge)Bonus: document the
color
andmonochrome
attributesThe text was updated successfully, but these errors were encountered: