Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
MNT: Introduce cmap(..., by_index=...) parameter#30548
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This allows to explicitly state whether inputs should be handled asnormalized values [0, 1] or indices into the colormap.The value `by_index='auto'` is the current default and makes theinterpretation dependent on the data type. Resulting in surprisingbehaviormatplotlib#28198. It is planned to deprecate this in a follow-up PR andswitch to`by_index=False` eventually. The standard case of float inputs will notbe affected by this change. But users that want to pass indices, willthen have to explicitly use `by_index=True`.
I don't really think#28198 is actually a problem and would leave the behavior as is, but if we're really going to change this (I'm only -0 but nowhere close to blocking) then I'd say that indexing should just be a new operation ( |
I think#28198 is a footgun that should be removed. Needing the upper-limit color of a colormap is not completely unlikely, and intuition suggests Ideally, Since for the time being we need indexing capability, at least I want to make that explict and not decidecall behavior based on the data type. You have two options for this, an additional paramter The |
Uh oh!
There was an error while loading.Please reload this page.
This allows to explicitly state whether inputs should be handled as normalized values [0, 1] or indices into the colormap.
The value
by_index='auto'
is the current default and makes the interpretation dependent on the data type. Resulting in surprising behavior#28198. It is planned to deprecate this in a follow-up PR and switch toby_index=False
eventually. The standard case of float inputs will not be affected by this change. But users that want to pass indices, will then have to explicitly useby_index=True
.Note: We currently rely on the auto detection for
BoundaryNorm
. That will be handled by special casingBoundaryNorm
in the colorizer pipeline, essentially switchingcmap(norm(data))
tocmap(norm(data), by_index=isinstance(norm, BoundaryNorm))
. It's better to do the special casing there rather than the type-based autodetection inColormap.__call__
. Hopefully, we can additionally get rid of that special case through#21911 (comment), but that's a separate discussion and its result does not impact the meaningfulness of this PR.