Title: Changing get_cmap to return copies of the registered colormaps. by greglucas · Pull Request #16943 · matplotlib/matplotlib · GitHub
Open Graph Title: Changing get_cmap to return copies of the registered colormaps. by greglucas · Pull Request #16943 · matplotlib/matplotlib
X Title: Changing get_cmap to return copies of the registered colormaps. by greglucas · Pull Request #16943 · matplotlib/matplotlib
Description: This is an alternative proposal compared to making Colormap objects themselves immutable as mentioned in #16296 (comment). I expect this to have some discussion about extensibility and future directions, so I consider this a proposal/idea PR. Previous discussion can be found in issues #16296 and #14645 Note that this isn't really deprecating anything, but it is changing some pretty significant behavior. I wasn't sure if it would need any deprecation/warnings put in somewhere, but figured that could wait until after some discussion as well. PR Summary Previously, calling plt.get_cmap() would return a pointer to the object, which would allow you to modify the built-ins unknowingly. cmap = plt.get_cmap('viridis').set_over('b') Previously, a second call to get the viridis colormap would return the modified colormap. cmap == plt.get_cmap('viridis') # True Now, it will return the original viridis built-in colormap. cmap == plt.get_cmap('viridis') # False Implications Accessing colormaps through the pyplot interface could still mess people up since it is a single object still. cmap = plt.cm.viridis cmap.set_over('b') cmap == plt.cm.viridis # True cmap == plt.cm.get_cmap('viridis') # False This also means that there are two copies of the colormap objects created initially now (one in cmap_d and a second deepcopy that I made for locals() to use with the pyplot interface. Is there a way to make the plt.cm.viridis object point to the function plt.get_cmap('viridis')? That may be and even nicer touch, but I couldn't think of anything quick off the top of my head. I had to add an equals method to Colormaps to compare lookup tables rather than object pointers that were done before. This will initialize the lookup table if it wasn't already previously, possibly leading to a little more overhead if people are comparing lots of colormaps. 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: This is an alternative proposal compared to making Colormap objects themselves immutable as mentioned in #16296 (comment). I expect this to have some discussion about extensibility and future direc...
X Description: This is an alternative proposal compared to making Colormap objects themselves immutable as mentioned in #16296 (comment). I expect this to have some discussion about extensibility and future direc...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/16943
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:552e418e-424d-0d2b-fcd7-73e691119735 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B6A2:37A81A:176B4DD:1FBD459:6A5359A3 |
| html-safe-nonce | f514f7ffbee2c37c5b081d883cce6bcd0cfa50086f9a2b9176f39811f0469334 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkEyOjM3QTgxQToxNzZCNEREOjFGQkQ0NTk6NkE1MzU5QTMiLCJ2aXNpdG9yX2lkIjoiMTQxNDcyODE0MzEwMDU0MzA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4a860111a90392bab406006275a6f3c92170efb650b5c5fd72123c69887d7028 |
| hovercard-subject-tag | pull_request:395127097 |
| 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/16943/files |
| twitter:image | https://avatars.githubusercontent.com/u/12417828?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/12417828?s=400&v=4 |
| og:image:alt | This is an alternative proposal compared to making Colormap objects themselves immutable as mentioned in #16296 (comment). I expect this to have some discussion about extensibility and future direc... |
| 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