Title: Modifying colormaps (as used in xarray) · Issue #16296 · matplotlib/matplotlib · GitHub
Open Graph Title: Modifying colormaps (as used in xarray) · Issue #16296 · matplotlib/matplotlib
X Title: Modifying colormaps (as used in xarray) · Issue #16296 · matplotlib/matplotlib
Description: xarray's plotting functionality sometimes needs to turn a colormap into a discrete colormap. I came across this in fixing a bug pydata/xarray#3601 where xarray was ignoring the effects of set_under(), etc., which had been called on the c...
Open Graph Description: xarray's plotting functionality sometimes needs to turn a colormap into a discrete colormap. I came across this in fixing a bug pydata/xarray#3601 where xarray was ignoring the effects of set_under...
X Description: xarray's plotting functionality sometimes needs to turn a colormap into a discrete colormap. I came across this in fixing a bug pydata/xarray#3601 where xarray was ignoring the effects of set_u...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/16296
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Modifying colormaps (as used in xarray)","articleBody":"`xarray`'s plotting functionality sometimes needs to turn a colormap into a discrete colormap. I came across this in fixing a bug https://github.com/pydata/xarray/pull/3601 where `xarray` was ignoring the effects of `set_under()`, etc., which had been called on the colormap. We've fixed that problem, but ended up with this https://github.com/pydata/xarray/blob/ae6609b025d62a0d863869cbd16db167a8855167/xarray/plot/utils.py#L94-L105\r\n```\r\n n_colors = len(levels) + ext_n - 1\r\n pal = _color_palette(cmap, n_colors)\r\n\r\n new_cmap, cnorm = mpl.colors.from_levels_and_colors(levels, pal, extend=extend)\r\n # copy the old cmap name, for easier testing\r\n new_cmap.name = getattr(cmap, \"name\", cmap)\r\n\r\n # copy colors to use for bad, under, and over values in case they have been set to\r\n # non-default values\r\n new_cmap._rgba_bad = getattr(cmap, \"_rgba_bad\", new_cmap._rgba_bad)\r\n new_cmap._rgba_under = getattr(cmap, \"_rgba_under\", new_cmap._rgba_under)\r\n new_cmap._rgba_over = getattr(cmap, \"_rgba_over\", new_cmap._rgba_over)\r\n```\r\nThis works, but is not particularly elegant, and if there are any other properties of the original `cmap` that we want to keep, we'd have to copy them over explicitly. @dcherian asked me to see if anyone on here could suggest a better way of modifying a `cmap` into a discrete `cmap`?","author":{"url":"https://github.com/johnomotani","@type":"Person","name":"johnomotani"},"datePublished":"2020-01-22T22:30:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/16296/matplotlib/issues/16296"}
| 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:4b6a080e-efba-faa4-dfa5-31a17ea34259 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCBA:30B94D:37D4E1:3959E8:6A519A68 |
| html-safe-nonce | 72ab769f525d4ec641dbe1659bbf34efa58e12ad1809d5385256777a98db18a0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0JBOjMwQjk0RDozN0Q0RTE6Mzk1OUU4OjZBNTE5QTY4IiwidmlzaXRvcl9pZCI6IjM4MTIzNzQ2NjYzNDcxMjUzNTIiLCJyZWdpb25fZWRnZSI6InNlYSIsInJlZ2lvbl9yZW5kZXIiOiJzZWEifQ== |
| visitor-hmac | 276d26dd1da1f4ba4ccc7e9da22d0f092f51c74342a5e28fc0681c52c7afaea2 |
| hovercard-subject-tag | issue:553832491 |
| 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/16296/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e521297b1250863b478bfa0a04f26b2da23ae061a9d6392568695c26f03307c5/matplotlib/matplotlib/issues/16296 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e521297b1250863b478bfa0a04f26b2da23ae061a9d6392568695c26f03307c5/matplotlib/matplotlib/issues/16296 |
| og:image:alt | xarray's plotting functionality sometimes needs to turn a colormap into a discrete colormap. I came across this in fixing a bug pydata/xarray#3601 where xarray was ignoring the effects of set_under... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | johnomotani |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width