Title: ENH: add shading='nearest' and 'auto' to `pcolormesh` by jklymak · Pull Request #16258 · matplotlib/matplotlib · GitHub
Open Graph Title: ENH: add shading='nearest' and 'auto' to `pcolormesh` by jklymak · Pull Request #16258 · matplotlib/matplotlib
X Title: ENH: add shading='nearest' and 'auto' to `pcolormesh` by jklymak · Pull Request #16258 · matplotlib/matplotlib
Description: PR Summary Redo of #9629. Lots of discussion there. See built example here: https://29535-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/gallery/images_contours_and_fields/pcolormesh_grids.html#sphx-glr-gallery-images-contours-and-fields-pcolormesh-grids-py Se new pcolormesh docs here: https://29535-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/api/_as_gen/matplotlib.axes.Axes.pcolormesh.html#matplotlib.axes.Axes.pcolormesh Suppose len(x) is N, len(y) is M, and size(C) is M, N. Previously, if shading='flat' then pcolor/mesh would silently drop the last row and column of C and x and y would specify the edges of the colorer quadrilaterals. While compatible with Matlab, this is both arbitrary, and probably not what the user wanted. This PR changes a few related things: if shading='flat' and the dimensions of x, y and C match, a Deprecation Warning is raised the data is no longer silently dropped. A new shading='nearest' is provided that only allows for x, y and C to match, and centers the colors on the grid points. A new shading='auto' is provided that will choose 'flat' or 'nearest' depending on the size of the data. A new rcParam['pcolor.shading'] is provided that defaults to 'flat' (for back compatibility). Demo: import numpy as np import matplotlib.pyplot as plt fig, axs = plt.subplots(3, 2, sharex=True, sharey=True) nx = 4 ny = 5 x = np.arange(nx) y = np.arange(ny) X, Y = np.meshgrid(x, y) np.random.seed(19680808) C = np.random.rand(ny, nx) # deprecation warning: axs[0, 0].pcolormesh(x, y, C, vmin=0, vmax=1, shading='flat') axs[0, 0].scatter(X[:], Y[:], c=C.flat, ec='w') axs[0, 0].set_title('flat: Emits deprecation warning') # no deprecation warning axs[0, 1].pcolormesh(x, y, C[:-1, :-1], vmin=0, vmax=1, shading='flat') axs[0, 1].scatter(X[:], Y[:], c=C.flat, ec='w') axs[0, 1].set_title('flat: No warning') # no deprecation warning axs[1, 0].pcolormesh(x, y, C, shading='nearest', vmin=0, vmax=1) axs[1, 0].scatter(X[:], Y[:], c=C.flat, ec='w') axs[1, 0].set_title('nearest') # no deprecation warning axs[1, 1].pcolormesh(x, y, C, shading='gouraud', vmin=0, vmax=1) axs[1, 1].scatter(X[:], Y[:], c=C.flat, ec='w') axs[1, 1].set_title('gouraud') axs[1, 1].set_xlim([-0.5, 3.5]) axs[1, 1].set_ylim([-0.5, 4.5]) # no deprecation warning: axs[2, 0].pcolormesh(x, y, C, vmin=0, vmax=1, shading='auto') axs[2, 0].scatter(X[:], Y[:], c=C.flat, ec='w') axs[2, 0].set_title('auto: matching size') # no deprecation warning axs[2, 1].pcolormesh(x, y, C[:-1, :-1], vmin=0, vmax=1, shading='auto') axs[2, 1].scatter(X[:], Y[:], c=C.flat, ec='w') axs[2, 1].set_title('auto: c smaller') The first call emits: testpcolormesh.py:17: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud' or set rcParams['pcolor.shading'] axs[0, 0].pcolormesh(x, y, C, vmin=0, vmax=1, shading='flat') PR Checklist Has Pytest style unit tests Code is Flake 8 compliant New features are documented, with examples if plot related Documentation is sphinx and numpydoc compliant Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there) Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way
Open Graph Description: PR Summary Redo of #9629. Lots of discussion there. See built example here: https://29535-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/gallery/images_contours_and_fields/...
X Description: PR Summary Redo of #9629. Lots of discussion there. See built example here: https://29535-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/gallery/images_contours_and_fields/...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/16258
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:81f49941-fccf-3957-40c5-d6b0993590c7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8BFC:333E4B:304A5F8:42653D9:6A54A828 |
| html-safe-nonce | 18674be274486b057a173ed6431ad875f8e3f020a18bced459a55b0b87ecec8e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QkZDOjMzM0U0QjozMDRBNUY4OjQyNjUzRDk6NkE1NEE4MjgiLCJ2aXNpdG9yX2lkIjoiMTE3NjMyMjgxMTc5NjY5NTA4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d399897c67ae56b0f0a4f6803d16c43d84e1cee3134fd4b5924a0b453436bbee |
| hovercard-subject-tag | pull_request:364476347 |
| 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/16258/files |
| twitter:image | https://avatars.githubusercontent.com/u/1562854?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1562854?s=400&v=4 |
| og:image:alt | PR Summary Redo of #9629. Lots of discussion there. See built example here: https://29535-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/gallery/images_contours_and_fields/... |
| 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 | f8cfff6384f62259baea531c7f58bc7040f8dd92 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width