-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm not sure how to add the check for whether c is indicating a color in a color cycle. I think it requires checking whether the first element of the string is Also: I'm not sure why those tests are failing, but it seems like the test server isn't connected to the internet..? |
There was a problem hiding this 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.
lib/matplotlib/colors.py
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
Co-authored-by: Oscar Gustafsson <[email protected]>
Looks like the CI failures were largely due to network problems on GHA/Azure so cycling to rerun |
BackgroundI 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 Current use of
|
I'm +0.5 on removing Before we can remove It should also be ensured, that |
There was a problem hiding this 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 whether grid.alpha
(the only use of _has_alpha_channel()
) should be deprecated. Also defer the decision on whether we need _has_alpha_channel_array()
.
lib/matplotlib/colors.py
Outdated
"""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""" |
There was a problem hiding this comment.
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 if c is not a valid color specifier.
There was a problem hiding this comment.
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.
lib/matplotlib/colors.py
Outdated
return False | ||
|
||
|
||
def _has_alpha_channel_array(cseq): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 are you still interested in working on this? |
Ah, yes! Lost track of it but I can continue in early January. Thanks for the reminder. |
See my responses to @timhoffm. I believe this is all that is needed now since you suggested deferring gridalpha discussion to another time? |
lib/matplotlib/colors.py
Outdated
return False | ||
|
||
|
||
def _has_alpha_channel_array(cseq): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 with is_color_like
and if not return False
. Then the remaining logic can be confident about how c
is structured.
Smart. I incorporated this. |
Co-authored-by: Tim Hoffmann <[email protected]>
Co-authored-by: Tim Hoffmann <[email protected]>
Co-authored-by: Ruth Comer <[email protected]>
There was a problem hiding this 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).
Co-authored-by: Tim Hoffmann <[email protected]>
Co-authored-by: Tim Hoffmann <[email protected]>
Co-authored-by: Tim Hoffmann <[email protected]>
Of course, no worries. In agreement with all and suggestions all accepted. |
Co-authored-by: Tim Hoffmann <[email protected]>
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. |
Thanks @landoskape and congratulations on your first PR merged into Matplotlib! We hope to hear from you again. |
Woohoo! Thanks :) |
PR summary
For more explanation see the matplotlib page on specifying colors.
PR checklist