Title: ENH: Extend gouraud shading to support data at quadrilateral centers by lucaznch · Pull Request #31362 · matplotlib/matplotlib · GitHub
Open Graph Title: ENH: Extend gouraud shading to support data at quadrilateral centers by lucaznch · Pull Request #31362 · matplotlib/matplotlib
X Title: ENH: Extend gouraud shading to support data at quadrilateral centers by lucaznch · Pull Request #31362 · matplotlib/matplotlib
Description: PR summary This PR extends the gouraud shading in Axes.pcolormesh to support data defined at the centers of quadrilaterals, where X and Y are one larger than Z in each dimension. In this situation, gouraud automatically converts the grid internally to match the data's shape by replacing each quadrilateral with a point at its center, computed as the average of its four corners, and then applies Gouraud shading. Why is this change necessary / what problem does it solve? pcolormesh with shading='gouraud' requires the data to be defined at the corners of quadrilaterals, meaning X, Y and Z must have the same shape. If the user is working with data defined at the centers, so that X and Y are one larger in each dimension, and tries to use shading='gouraud' for a smooth color interpolation, a TypeError is raised. This now allows pcolormesh to provide both constant and linearly interpolated shading for each data/grid configuration. Shading can be switched for the same data location, allowing switches between nearest and gouraud, and now also between flat and gouraud. constant linearly interpolated data at grid quad corners (X, Y, Z same shape) nearest gouraud data at grid quad centers (X, Y one larger than Z) flat gouraud What is the reasoning for this implementation? Following discussion on the issue and in this PR, the approach taken is to extend the existing gouraud shading. Edit: The initial version of this PR introduced a new shading, called centered-gouraud, in pcolormesh. This shading was a variant of gouraud dedicated to handle the case of data defined at quadrilateral centers (with X and Y one larger than Z), by performing the same grid conversion described above. Following discussion in this PR, the approach was revised to extend the existing gouraud shading instead. Example nrows, ncols = 3, 5 Z = np.arange(nrows * ncols).reshape(nrows, ncols) x = np.arange(ncols + 1) y = np.arange(nrows + 1) _, axs = plt.subplots(2, 2, layout='constrained') # Data at corners, requires X and Y the same shape as Z. axs[0, 0].pcolormesh(x[:-1], y[:-1], Z, shading='nearest') axs[0, 1].pcolormesh(x[:-1], y[:-1], Z, shading='gouraud') # Data at centers, requires X and Y one larger than Z. axs[1, 0].pcolormesh(x, y, Z, shading='flat') axs[1, 1].pcolormesh(x, y, Z, shading='gouraud') # works now Closes #8422 AI Disclosure I used AI tools to help proofread and improve the grammar of this PR description. The code logic and implementation are my own. PR checklist "closes #0000" is in the body of the PR description to link the related issue new and changed code is tested Plotting related features are demonstrated in an example New Features and API Changes are noted with a directive and release note Documentation complies with general and docstring guidelines
Open Graph Description: PR summary This PR extends the gouraud shading in Axes.pcolormesh to support data defined at the centers of quadrilaterals, where X and Y are one larger than Z in each dimension. In this situation,...
X Description: PR summary This PR extends the gouraud shading in Axes.pcolormesh to support data defined at the centers of quadrilaterals, where X and Y are one larger than Z in each dimension. In this situation,...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/31362
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:7e158ee8-b3f9-083c-1905-b2d8875bbe72 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D0EE:B2127:1F8193:2ABCBF:6A526A82 |
| html-safe-nonce | d87625fc88c2ecbc2bfa5b16f75928e63120cc554e8b7936bb29508683f6ce6a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMEVFOkIyMTI3OjFGODE5MzoyQUJDQkY6NkE1MjZBODIiLCJ2aXNpdG9yX2lkIjoiNzI1MjI0MTc4MzYyNjgyMDIyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e4a73fcb318894bcc8c8a99ca6ae49bf1e059048d2d842593b5704e91cd37e5a |
| hovercard-subject-tag | pull_request:3437953771 |
| 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/31362/files |
| twitter:image | https://avatars.githubusercontent.com/u/104226137?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/104226137?s=400&v=4 |
| og:image:alt | PR summary This PR extends the gouraud shading in Axes.pcolormesh to support data defined at the centers of quadrilaterals, where X and Y are one larger than Z in each dimension. In this situation,... |
| 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