MNT: Introduce cmap(..., by_index=...) parameter #30548
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.