Title: [Doc]: Preferred way of specifying colormaps via `cmap` · Issue #28915 · matplotlib/matplotlib · GitHub
Open Graph Title: [Doc]: Preferred way of specifying colormaps via `cmap` · Issue #28915 · matplotlib/matplotlib
X Title: [Doc]: Preferred way of specifying colormaps via `cmap` · Issue #28915 · matplotlib/matplotlib
Description: Documentation Link No response Problem We have three four ways: cmap="magma" cmap=plt.cm.magma cmap=plt.colormaps["magma"] cmap=plt.get_cmap("magma") Suggested improvement I'd like to advertise the str version, because it's very readable...
Open Graph Description: Documentation Link No response Problem We have three four ways: cmap="magma" cmap=plt.cm.magma cmap=plt.colormaps["magma"] cmap=plt.get_cmap("magma") Suggested improvement I'd like to advertise the...
X Description: Documentation Link No response Problem We have three four ways: cmap="magma" cmap=plt.cm.magma cmap=plt.colormaps["magma"] cmap=plt.get_cmap("magma") Suggested improve...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28915
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Doc]: Preferred way of specifying colormaps via `cmap`","articleBody":"### Documentation Link\r\n\r\n_No response_\r\n\r\n### Problem\r\n\r\nWe have \u003cs\u003ethree\u003c/s\u003e four ways:\r\n\r\n1) `cmap=\"magma\"`\r\n2) `cmap=plt.cm.magma`\r\n3) `cmap=plt.colormaps[\"magma\"]`\r\n4) `cmap=plt.get_cmap(\"magma\")`\r\n\r\n### Suggested improvement\r\n\r\nI'd like to advertise the str version, because it's very readable and less to type. Disadvantage is that you could mis-type (but we have str parameter all over the place) and that you have to separately learn one of the others if you need the colormap explicitly.\r\n\r\nI'd like to down-prioritize the `plt.cm.*` version. While it's too widely used so that we cannot deprecate, having the colormaps as names on the module level does not scale. It only works for builtin colormaps but not for ones that are registered by the user.\r\n\r\nSo the recommendation would be:\r\n- Use str colormap names on `cmap` arguments.\r\n- Use `plt.colormaps[name]` to get the colormap instance.\r\n\r\nNoted here: https://matplotlib.org/devdocs/users/next_whats_new/diverging_colormaps.html, which should be changed if we agree on the recommendation.","author":{"url":"https://github.com/timhoffm","@type":"Person","name":"timhoffm"},"datePublished":"2024-10-01T09:00:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/28915/matplotlib/issues/28915"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f1d2f380-1d13-3d61-17cc-5b68128403fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1E6:1C3DD7:103880A:15C72DD:6A5297B0 |
| html-safe-nonce | 307185a771177b1ed88ac3d5f0f9741b9f79d050d66b61965e3f6bf1f19b2072 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUU2OjFDM0RENzoxMDM4ODBBOjE1QzcyREQ6NkE1Mjk3QjAiLCJ2aXNpdG9yX2lkIjoiODgwMTc5MTAwMjQ4NDU3ODIyNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9016f693f01474b0f16990e703e58425260bf2227ed5f73a5ec2c05d3abb401c |
| hovercard-subject-tag | issue:2558614394 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/matplotlib/matplotlib/28915/issue_layout |
| twitter:image | https://opengraph.githubassets.com/108646fc0d9d23527bf369ccbdf64691aeec8ae2b22fab5709848c2a7267b757/matplotlib/matplotlib/issues/28915 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/108646fc0d9d23527bf369ccbdf64691aeec8ae2b22fab5709848c2a7267b757/matplotlib/matplotlib/issues/28915 |
| og:image:alt | Documentation Link No response Problem We have three four ways: cmap="magma" cmap=plt.cm.magma cmap=plt.colormaps["magma"] cmap=plt.get_cmap("magma") Suggested improvement I'd like to advertise the... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | timhoffm |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| 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