Title: Fixed bilinear interpolation for `SegmentedBivarColormap` by ayshih · Pull Request #30824 · matplotlib/matplotlib · GitHub
Open Graph Title: Fixed bilinear interpolation for `SegmentedBivarColormap` by ayshih · Pull Request #30824 · matplotlib/matplotlib
X Title: Fixed bilinear interpolation for `SegmentedBivarColormap` by ayshih · Pull Request #30824 · matplotlib/matplotlib
Description: PR summary The lookup table generated by SegmentedBivarColormap is slightly inaccurate. Most notably, the darkest color in the lookup table is not as dark as the darkest color in the input, and the same goes for the brightest color. This has been glossed over in the tests due to the liberal use of atol. >>> from matplotlib.cm import bivar_cmaps >>> cmap = bivar_cmaps['BiOrangeBlue'] >>> print(cmap.patch[0, 0, :]) [0. 0. 0.] >>> print(cmap.patch[-1, 0, :]) [1. 0.5 0. ] >>> print(cmap.patch[-1, -1, :]) [1. 1. 1.] >>> print(cmap.lut[0, 0, :]) [0.00244141 0.00242224 0.00244141 1. ] >>> print(cmap.lut[-1, 0, :]) [0.99853516 0.50048437 0.00244141 1. ] >>> print(cmap.lut[-1, -1, :]) [0.99853516 0.99854675 0.99853516 1. ] SegmentedBivarColormap uses the image-plotting resampler (Agg) to perform bilinear interpolation, and these inaccuracies result from a bug in the transform definition plus a second bug that would be fixed by #30184. However, just fixing these two bugs is not a good solution. The Agg resampler – which is intended for producing good-enough images for visual display – is problematic because it divides each pixel into 256 subpixels, which means it internally calculates 256 * M - 1 intermediate color candidates between the end colors, but the color table wants 254 intermediate colors between the end colors (to get 256 colors in total). That means fixing the aforementioned two bugs results in a non-smooth color table because 254 does not divide into 256 * M - 1 cleanly. So, this PR instead takes the approach of eschewing the Agg resampler entirely and performing the bilinear interpolation using straight NumPy. Now the extreme colors are exactly what they should be. I'll note that the tests still need to use a bit of atol because the definition of BiOrangeBlue uses input that is rounded to 3 decimal places. Update: now fixed. >>> from matplotlib.cm import bivar_cmaps >>> cmap = bivar_cmaps['BiOrangeBlue'] >>> print(cmap.patch[0, 0, :]) [0. 0. 0.] >>> print(cmap.patch[-1, 0, :]) [1. 0.5 0. ] >>> print(cmap.patch[-1, -1, :]) [1. 1. 1.] >>> print(cmap.lut[0, 0, :]) [0. 0. 0. 1.] >>> print(cmap.lut[-1, 0, :]) [1. 0.5 0. 1. ] >>> print(cmap.lut[-1, -1, :]) [1. 1. 1. 1.] 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 The lookup table generated by SegmentedBivarColormap is slightly inaccurate. Most notably, the darkest color in the lookup table is not as dark as the darkest color in the input, and t...
X Description: PR summary The lookup table generated by SegmentedBivarColormap is slightly inaccurate. Most notably, the darkest color in the lookup table is not as dark as the darkest color in the input, and t...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/30824
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:ebdc1733-08e5-5887-1b42-f14548a82841 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 82C8:1B2073:1A9B8A7:235452B:6A52CE36 |
| html-safe-nonce | 28a7a08046dbccbf18eb3fd327e4a5ca3f58ad622bf9eefc3c81a88d837c8286 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkM4OjFCMjA3MzoxQTlCOEE3OjIzNTQ1MkI6NkE1MkNFMzYiLCJ2aXNpdG9yX2lkIjoiNDg0NjI1Njc3NTc3MzczNjUwMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 44a09ec4dd09ddcea11af6744f64dfffb8cd767ea56fdb4f134114da1e0ce13f |
| hovercard-subject-tag | pull_request:3082622890 |
| 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/30824/files |
| twitter:image | https://avatars.githubusercontent.com/u/991759?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/991759?s=400&v=4 |
| og:image:alt | PR summary The lookup table generated by SegmentedBivarColormap is slightly inaccurate. Most notably, the darkest color in the lookup table is not as dark as the darkest color in the input, and t... |
| 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