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

ENH: Add bad, under, over kwargs to Colormap#29460

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

Merged
timhoffm merged 1 commit intomatplotlib:mainfromtimhoffm:colormap-bad-under-over
Jan 24, 2025

Conversation

timhoffm
Copy link
Member

This is part of the effort for making Colormaps immutable (#29141). Obviously, we can only get immutable in the future if the bad, under, over colors can already be set upon creation.

@@ -1215,6 +1247,18 @@ class ListedColormap(Colormap):
N > len(colors)

the list will be extended by repetition.

.. deprecated:: 3.11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This seems orthogonal to this PR? Or is this already deprecated elsewhere and this is just a doc cleanup? I'm not really following why we would need to do this.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The deprecation is in#29135, it's indeed unrelated. I just noticed that I haven't added this to the parameter docs, and didn't bother to make a separate PR since I was editing that position in the docstring anyway. Sorry for the confusion.

jklymak reacted with thumbs up emoji
@timhoffmtimhoffmforce-pushed thecolormap-bad-under-over branch from0ab0843 todfb2f68CompareJanuary 11, 2025 23:15
@timhoffmtimhoffm added this to thev3.11.0 milestoneJan 11, 2025
Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not 100% sure about immutability of colormaps, but this addition seems helpful even with the current state of things.

@timhoffm
Copy link
MemberAuthor

The annoying thing with mutable colormaps is that we always have to do copies when returning colormaps from the , because a user could docmap = plt.colormaps['viridis']; cmap.set_over('red') and we don't want users to modify the global colormaps. Likewise, but more subtile: Forplt.imshow(a, cmap=my_cmap); my_cmap.set_over('red'); plt.imshow(b, cmap=my_cmap) should the over value be applied in the first image?

Changes to colormaps are relatively rare. The most prominent ones are over/under/bad, but again most of them are just setup-time changes (and done separately because the constructor did not supply them). Conceptually a colormap with a given name is fixed. You don't want it to behave differently at different. Therefore, immutability is logically helpful here, and immutable objects are much easier to maintain and reason about.

"""
Parameters
----------
name : str
The name of the colormap.
N : int
The number of RGB quantization levels.
bad : :mpltype:`color`, default: transparent
The color for invalid values (NaN or masked).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
Thecolorforinvalidvalues (NaNormasked).
Thecolorforinvalidvalues (NaNormasked).
..versionadded::3.11

? (Likewise in many locations below. Hence, maybe it is not required...)

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done. It's a bit verbose, but OTOH it's good to be explicit about this.

Copy link
Member

@oscargusoscargus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Subject to deciding if the.. versionadded:: should be added. Feel free to self merge when you have decided.

This is part of the effort for making Colormaps immutable (matplotlib#29141).Obviously, we can only get immutable in the future if thebad, under, over colors can already be set upon creation.
@timhoffmtimhoffmforce-pushed thecolormap-bad-under-over branch fromdfb2f68 toe1adce7CompareJanuary 24, 2025 09:52
@timhoffmtimhoffm merged commit0a0b9ac intomatplotlib:mainJan 24, 2025
41 checks passed
@timhoffmtimhoffm deleted the colormap-bad-under-over branchJanuary 24, 2025 12:09
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jklymakjklymakjklymak approved these changes

@oscargusoscargusoscargus approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

3 participants
@timhoffm@jklymak@oscargus

[8]ページ先頭

©2009-2025 Movatter.jp