Update for checking whether colors have an alpha channel#27327
Update for checking whether colors have an alpha channel#27327rcomer merged 16 commits intomatplotlib:mainfrom landoskape:alpha-channel-update
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..? |
oscargus
left a comment
There was a problem hiding this comment.
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.
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.
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 <oscar.gustafsson@gmail.com>
|
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 |
timhoffm
left a comment
There was a problem hiding this comment.
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.
We should mention that the result is undefined if c is not a valid color specifier.
There was a problem hiding this comment.
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.
This is not used anywhere right now. Therefore, we don't need it here.
There was a problem hiding this comment.
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.
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.
Um, you've just introduced this function and immediately deprecated it?!? You should simply not add it to the PR.
Smart. I incorporated this. |
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>
timhoffm
left a comment
There was a problem hiding this comment.
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 <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>
|
Of course, no worries. In agreement with all and suggestions all accepted. |
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
|
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