Title: [Bug]: The method for checking whether a color has an alpha value is outdated · Issue #27321 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: The method for checking whether a color has an alpha value is outdated · Issue #27321 · matplotlib/matplotlib
X Title: [Bug]: The method for checking whether a color has an alpha value is outdated · Issue #27321 · matplotlib/matplotlib
Description: Bug summary In matplotlib.colors._has_alpha_channel, it fails to identify colors with alpha channels in two contexts. It assumes that any color specified as a string doesn't have an alpha channel. This is outdated, because hex strings th...
Open Graph Description: Bug summary In matplotlib.colors._has_alpha_channel, it fails to identify colors with alpha channels in two contexts. It assumes that any color specified as a string doesn't have an alpha channel. ...
X Description: Bug summary In matplotlib.colors._has_alpha_channel, it fails to identify colors with alpha channels in two contexts. It assumes that any color specified as a string doesn't have an alpha chann...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/27321
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: The method for checking whether a color has an alpha value is outdated","articleBody":"### Bug summary\r\n\r\nIn [matplotlib.colors._has_alpha_channel](https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/colors.py#L234), it fails to identify colors with alpha channels in two contexts. \r\n\r\n1. It assumes that any color specified as a string doesn't have an alpha channel. This is outdated, because hex strings that contain alpha values are permitted. \r\n2. It assumes that tuples indicating the color and the alpha don't have alpha channels. This is because it assumes that the length has to be 4 for a non-string with an alpha channel.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib.colors as mcolors\r\n\r\ncolor = '#0f0f0f80'\r\nprint(mcolors._has_alpha_channel(color))\r\n\r\ncolor = ('r', 0.5)\r\nprint(mcolors._has_alpha_channel(color))\r\n```\r\n\r\n\r\n### Actual outcome\r\n```\r\nFalse\r\nFalse\r\n```\r\n\r\n### Expected outcome\r\n```\r\nTrue\r\nTrue\r\n```\r\n\r\n### Additional information\r\n\r\nI can imagine a few fixes, but the code for creating an RGBA array from a color is a bit opaque to me. Also, the method is currently only used in lib/matplotlib/axis.py for the Tick class and in lib/matplotlib/test_colors.py. So maybe it's not that important, but it could be more useful if more flexible and accurate.\r\n\r\nMotivation:\r\nThe motivation for this bug issue is the context where the alpha value should be set to a default value if the alpha is not provided by the user. This context would benefit greatly from a method that accurately determines whether a color or a sequence of colors have alpha values. \r\n\r\n### Operating system\r\n\r\nOS/X\r\n\r\n### Matplotlib Version\r\n\r\n3.9.0.dev687+g4099a45ee5\r\n\r\n### Matplotlib Backend\r\n\r\nMacOSX\r\n\r\n### Python version\r\n\r\n3.10.12\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\nNone","author":{"url":"https://github.com/landoskape","@type":"Person","name":"landoskape"},"datePublished":"2023-11-14T08:42:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/27321/matplotlib/issues/27321"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:04e193d5-2bbf-4bff-fb59-76ac82d9a31a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D8E6:1ED62B:A0444F:D960D1:6A5201DF |
| html-safe-nonce | c8eba8821ea1f953905c4fc72729c22bd2a451419e029f3a40fa54e750cbc83b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOEU2OjFFRDYyQjpBMDQ0NEY6RDk2MEQxOjZBNTIwMURGIiwidmlzaXRvcl9pZCI6IjMzMDg4NjExOTMzNzcxNTM1MDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 82c95d41118b5c1a22a202ff26fc754053b7d8555c05714739fb722f5386d81d |
| hovercard-subject-tag | issue:1992252625 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/27321/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a05bacb3b333ee52a0a19168a7382ccffef6ded6b60390b7940727eced07640f/matplotlib/matplotlib/issues/27321 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a05bacb3b333ee52a0a19168a7382ccffef6ded6b60390b7940727eced07640f/matplotlib/matplotlib/issues/27321 |
| og:image:alt | Bug summary In matplotlib.colors._has_alpha_channel, it fails to identify colors with alpha channels in two contexts. It assumes that any color specified as a string doesn't have an alpha channel. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | landoskape |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width