Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
timhoffm wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromtimhoffm:cmap-index

Conversation

timhoffm
Copy link
Member

@timhoffmtimhoffm commentedSep 11, 2025
edited
Loading

This allows to explicitly state whether inputs should be handled as normalized values [0, 1] or indices into the colormap.

The valueby_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 to
by_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 forBoundaryNorm. 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.

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`.
@anntzer
Copy link
Contributor

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 (cmap[idx] -- which seems best to me -- orcmap.colors[idx], as discussed in the issue thread), not a flag on__call__.

@timhoffm
Copy link
MemberAuthor

I think#28198 is a footgun that should be removed. Needing the upper-limit color of a colormap is not completely unlikely, and intuition suggestscmap(1). It's completely non-obvious that you need to docmap(1.).

Ideally,Colormap.__call__ would always expect values in the range [0, 1]. But we need indexing capability to support the awkwardBoundaryNorm. While I'd like to get rid of that, the discussion is still open, see#21911, and anyway that'd be a more long-term project.

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 paramterby_index, or a separate functioncmap.by_index(X, alpha=None, bytes=False)(note that[idx]is not sufficient because we need to support the extra parameters to keep full functionality forBoundaryNorm` use cases).

Theby_index kwarg is the simpler implementation. Aby_index() function would also be possible, but needs more internal rearchitecting of Colormap.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@timhoffm@anntzer

[8]ページ先頭

©2009-2025 Movatter.jp