Title: Fix Axes.grid() to respect alpha in color tuples by Nabeelshar · Pull Request #30849 · matplotlib/matplotlib · GitHub
Open Graph Title: Fix Axes.grid() to respect alpha in color tuples by Nabeelshar · Pull Request #30849 · matplotlib/matplotlib
X Title: Fix Axes.grid() to respect alpha in color tuples by Nabeelshar · Pull Request #30849 · matplotlib/matplotlib
Description: PR summary This PR fixes issue #22231 where ax.grid(color=(R, G, B, A)) ignores the alpha channel in color tuples, causing gridlines to appear fully opaque instead of with the specified transparency. Problem: When calling ax.grid(color=(0.8, 0.8, 0.8, 0.2)), the gridlines appeared with alpha=1.0 instead of alpha=0.2. Root Cause: The issue occurred in two places in lib/matplotlib/axis.py: Tick.__init__: When creating ticks with a color containing alpha, the code didn't extract the alpha value from the color tuple Tick._apply_params: When updating gridlines via grid(), color tuples with alpha weren't being decomposed Solution: Extract alpha from color tuples using mcolors.to_rgba() and set color (RGB) and alpha separately, ensuring proper alpha precedence: explicit alpha parameter > color tuple alpha > rcParams. Minimum example demonstrating the fix: import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([0, 1], [0, 1]) ax.grid(True, color=(0.8, 0.8, 0.8, 0.2)) # Alpha=0.2 now works! plt.show() closes #22231 PR checklist "closes #22231" is in the body of the PR description to link the related issue new and changed code is tested (added test_grid_color_with_alpha) [N/A] Plotting related features are demonstrated in an example (bug fix, not new feature) [N/A] New Features and API Changes are noted with a directive and release note (bug fix, not API change) Documentation complies with general and docstring guidelines (no docstring changes needed)
Open Graph Description: PR summary This PR fixes issue #22231 where ax.grid(color=(R, G, B, A)) ignores the alpha channel in color tuples, causing gridlines to appear fully opaque instead of with the specified transparenc...
X Description: PR summary This PR fixes issue #22231 where ax.grid(color=(R, G, B, A)) ignores the alpha channel in color tuples, causing gridlines to appear fully opaque instead of with the specified transparenc...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/30849
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:81a7eafb-3a67-8293-8a38-b859fd925691 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | EB68:18D14E:9072:B04C:6A53228A |
| html-safe-nonce | e897bbcdec9a3aafcdff2874da54cc07fe29352a8042dbb357eadc9f62a0a8f4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjY4OjE4RDE0RTo5MDcyOkIwNEM6NkE1MzIyOEEiLCJ2aXNpdG9yX2lkIjoiMjQ4MTM0MzcyNDEyODUxMDYwMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e171d2f4fd7c6e63b7fcb9e857b345fd5212138505155e612e3e36bd11ca1408 |
| hovercard-subject-tag | pull_request:3098393615 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/matplotlib/matplotlib/pull/30849/files |
| twitter:image | https://avatars.githubusercontent.com/u/96086329?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/96086329?s=400&v=4 |
| og:image:alt | PR summary This PR fixes issue #22231 where ax.grid(color=(R, G, B, A)) ignores the alpha channel in color tuples, causing gridlines to appear fully opaque instead of with the specified transparenc... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width