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

Update for checking whether colors have an alpha channel#27327

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
rcomer merged 16 commits intomatplotlib:mainfromlandoskape:alpha-channel-update
Jan 6, 2025
Merged

Update for checking whether colors have an alpha channel#27327

rcomer merged 16 commits intomatplotlib:mainfromlandoskape:alpha-channel-update
Jan 6, 2025

Conversation

landoskape
Copy link
Contributor

@landoskapelandoskape commentedNov 15, 2023
edited
Loading

PR summary

  • Update check of whether a color has an alpha channel to include hexadecimal and color/alpha tuple formats.
  • Add test of the new formats
  • Add method to check whether a sequence of colors has an alpha channel

For more explanation see the matplotlib page onspecifying colors.

PR checklist

@landoskape
Copy link
ContributorAuthor

I'm not sure how to add the check for whetherc is indicating a color in a color cycle. I think it requires checking whether the first element of the string is'C' and if the next elements represent a digit.

Also: I'm not sure why those tests are failing, but it seems like the test server isn't connected to the internet..?

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.

I think it makes sense to make this more general. Some comments to consider.

return not isinstance(c, str) and len(c) == 4
# If c is not a color, it doesn't have an alpha channel
if not is_color_like(c):
return False
Copy link
Member

Choose a reason for hiding this comment

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

One should probably check the code if this has already been called. Since this is a private method one can require that it is checked.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Hm, I'm sure I know how to do that or what you mean. Would you explain a little more?

(also, thanks for the comments, as always)

landoskapeand others added2 commitsNovember 15, 2023 09:00
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
@ksunden
Copy link
Member

Looks like the CI failures were largely due to network problems on GHA/Azure so cycling to rerun

@ksundenksunden reopened thisNov 21, 2023
@landoskape
Copy link
ContributorAuthor

Background

I opened this PR because of my work on PR#27304, which I though would benefit from a check on whether the user provided a color with an alpha value to determine how the violinplot function handles alpha values. However, after@story645 explained, the point of allowing alpha to be included in a color was to remove unnecessary arguments, which I agree with, so that sort of makes my work here less relevant (except for the fact that the previous_has_alpha_channel() was out of date).

Current use of_has_alpha_channel()

The_has_alpha_channel() method is only used in one place throughout the entire library:lib/matplotlib/axis.Tick. In that location, it just checks whether the provided grid color has an alpha channel specified, and if not, usesmpl.rcParams["grid.alpha"] instead.

Tick() is the parent ofXTick() andYTick(), which are the parents ofSkewXTick(). However, nowhere in the entire library do those methods set the kwargsgrid_color orgrid_alpha.

Proposal

It seems like_has_alpha_channel() is obsolete, and should be removed from the library. I propose:

  1. Removing it (and it's tests intest_colors.py).
  2. InTick(), removinggrid_alpha as an argument and lettinggrid_color specify the alpha setting.
story645 reacted with thumbs up emoji

@timhoffm
Copy link
Member

I'm +0.5 on removinggrid_alpha. There's value in reducing the number of parameters an dependency between them. While we should not remove primaryalpha parameters from functions because they are used too widely, removing*_alpha parameters for secondary color attributes (typically pass through) seems viable.

Before we can removegrid_alpha, it has to go through our deprecation cycle.

It should also be ensured, thatgrid_color=(None, 0.5) works and only modifies the alpha. Otherwise, only modifying the alpha becomes cumbersome.

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

I suggest to take the fixed_has_alpha_channel() as minimal bugfix and defer the discussion whethergrid.alpha (the only use of_has_alpha_channel()) should be deprecated. Also defer the decision on whether we need_has_alpha_channel_array().

"""Return whether *c* is a color with an alpha channel."""
# 4-element sequences are interpreted as r, g, b, a
return not isinstance(c, str) and len(c) == 4
"""Return whether *c* is a color with an alpha channel"""
Copy link
Member

Choose a reason for hiding this comment

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

We should mention that the result is undefined ifc is not a valid color specifier.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This is now mentioned in the docstring and the comment for the final return line.

return False


def _has_alpha_channel_array(cseq):
Copy link
Member

Choose a reason for hiding this comment

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

This is not used anywhere right now. Therefore, we don't need it here.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

It is now deprecated (I added the standard _api.deprecated decorator). In addition I added a deprecation file in the doc/ folder.

Copy link
Member

Choose a reason for hiding this comment

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

Um, you've just introduced this function and immediately deprecated it?!? You should simply not add it to the PR.

landoskape reacted with eyes emoji
@rcomer
Copy link
Member

@landoskape are you still interested in working on this?

@landoskape
Copy link
ContributorAuthor

Ah, yes! Lost track of it but I can continue in early January. Thanks for the reminder.

rcomer reacted with thumbs up emoji

@landoskape
Copy link
ContributorAuthor

See my responses to@timhoffm. I believe this is all that is needed now since you suggested deferring gridalpha discussion to another time?

return False


def _has_alpha_channel_array(cseq):
Copy link
Member

Choose a reason for hiding this comment

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

Um, you've just introduced this function and immediately deprecated it?!? You should simply not add it to the PR.

landoskape reacted with eyes emoji
Copy link
Member

@rcomerrcomer left a comment
edited
Loading

Choose a reason for hiding this comment

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

I suggest starting by checking whether we have a valid color withis_color_like and if not returnFalse. Then the remaining logic can be confident about howc is structured.

@landoskape
Copy link
ContributorAuthor

Ah -@timhoffm good point! The function was introduced because it would have helped the violinplot update that is in PR#27304. It's now removed entirely.

@landoskape
Copy link
ContributorAuthor

I suggest starting by checking whether we have a valid color withis_color_like and if not returnFalse. Then the remaining logic can be confident about howc is structured.

Smart. I incorporated this.

landoskapeand others added5 commitsJanuary 4, 2025 18:12
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

Sorry, after going through the logic carefully, I've some additional remarks. (Could/should have been part of the previous review).

landoskapeand others added3 commitsJanuary 5, 2025 00:03
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@landoskape
Copy link
ContributorAuthor

Of course, no worries. In agreement with all and suggestions all accepted.

landoskapeand others added2 commitsJanuary 6, 2025 15:45
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@rcomerrcomer added this to thev3.11.0 milestoneJan 6, 2025
@rcomer
Copy link
Member

I do not know what the doc failure is about, but it cannot possibly be caused by this change since we are only modifying a private function.

@rcomerrcomer merged commit9bb047d intomatplotlib:mainJan 6, 2025
35 of 36 checks passed
@rcomer
Copy link
Member

Thanks@landoskape and congratulations on your first PR merged into Matplotlib! We hope to hear from you again.

story645 and landoskape reacted with rocket emoji

@landoskape
Copy link
ContributorAuthor

Woohoo! Thanks :)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@oscargusoscargusoscargus left review comments

@timhoffmtimhoffmtimhoffm approved these changes

@rcomerrcomerrcomer approved these changes

Assignees
No one assigned
Projects
Status: Waiting for author
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

[Bug]: The method for checking whether a color has an alpha value is outdated
5 participants
@landoskape@ksunden@timhoffm@rcomer@oscargus

[8]ページ先頭

©2009-2025 Movatter.jp