Title: colorbar shows no ticks for decreasing norms · Issue #12665 · matplotlib/matplotlib · GitHub
Open Graph Title: colorbar shows no ticks for decreasing norms · Issue #12665 · matplotlib/matplotlib
X Title: colorbar shows no ticks for decreasing norms · Issue #12665 · matplotlib/matplotlib
Description: Bug report Bug summary When using a decreasing Norm, colorbars show no ticks. Code for reproduction This example uses a PowerNorm-like norm which first applies the power, then does linear rescaling to (0, 1) (as opposed to matplotlib's P...
Open Graph Description: Bug report Bug summary When using a decreasing Norm, colorbars show no ticks. Code for reproduction This example uses a PowerNorm-like norm which first applies the power, then does linear rescaling...
X Description: Bug report Bug summary When using a decreasing Norm, colorbars show no ticks. Code for reproduction This example uses a PowerNorm-like norm which first applies the power, then does linear rescaling...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/12665
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"colorbar shows no ticks for decreasing norms","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\n\r\nWhen using a decreasing Norm, colorbars show no ticks.\r\n\r\n**Code for reproduction**\r\n\r\nThis example uses a PowerNorm-like norm which first applies the power, then does linear rescaling to (0, 1) (as opposed to matplotlib's PowerNorm which first linearly rescales to (0, 1) then applies the power) -- as argued in #10234 the behavior here is often more desirable, though that's not the point of this bug report.\r\n\r\nPNorms with a negative gamma are decreasing (the builtin PowerNorm wouldn't work here because the first linear rescaling step would put the minimum to zero, which doesn't like being raised to a negative power...).\r\n\r\n```python\r\nfrom matplotlib import pyplot as plt\r\nfrom matplotlib.colors import Normalize\r\nimport numpy as np\r\n\r\n\r\nclass PNorm(Normalize):\r\n def __init__(self, vmin=None, vmax=None, clip=False, *, gamma):\r\n super().__init__(vmin=vmin, vmax=vmax, clip=clip)\r\n self.gamma = gamma\r\n\r\n def __call__(self, value, clip=None):\r\n if clip is None:\r\n clip = self.clip\r\n result, is_scalar = self.process_value(value)\r\n self.autoscale_None(result)\r\n vmin, vmax = self.vmin, self.vmax\r\n gamma = self.gamma\r\n if vmin \u003e vmax:\r\n raise ValueError(\"minvalue must be less than or equal to maxvalue\")\r\n elif vmin == vmax:\r\n result.fill(0)\r\n else:\r\n if clip:\r\n mask = np.ma.getmask(result)\r\n result = np.ma.array(np.clip(result.filled(vmax), vmin, vmax),\r\n mask=mask)\r\n resdat = result.data\r\n resdat = resdat ** gamma\r\n resdat -= min(vmin ** gamma, vmax ** gamma)\r\n resdat /= abs(vmax ** gamma - vmin ** gamma)\r\n result = np.ma.array(resdat, mask=result.mask, copy=False)\r\n if is_scalar:\r\n result = result[0]\r\n return result\r\n\r\n def inverse(self, value):\r\n if not self.scaled():\r\n raise ValueError(\"Not invertible until scaled\")\r\n if np.iterable(value):\r\n return np.vectorize(self.inverse)(value)\r\n else:\r\n vmin, vmax = self.vmin, self.vmax\r\n gamma = self.gamma\r\n return (value * abs(vmax ** gamma - vmin ** gamma)\r\n + min(vmin ** gamma, vmax ** gamma)) ** (1 / gamma)\r\n\r\n\r\nfig, axs = plt.subplots(1, 2)\r\nim = axs[0].imshow(np.arange(1., 101.).reshape((10, 10)), norm=PNorm(gamma=2))\r\nfig.colorbar(im, ax=axs[0])\r\nim = axs[1].imshow(np.arange(1., 101.).reshape((10, 10)), norm=PNorm(gamma=-2))\r\nfig.colorbar(im, ax=axs[1])\r\n\r\nplt.show()\r\n```\r\n\r\n(as a side note, creating new norms is a bit ridiculously verbose)\r\n\r\n**Actual outcome**\r\n\r\nleft is gamma=2, right is gamma=-2.\r\n\r\n\r\n\r\n**Expected outcome**\r\n\r\nSome ticks on the right (gamma=-2) colorbar.\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: Arch Linux\r\n * Matplotlib version: 3.0.1\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): any\r\n * Python version: 3.7","author":{"url":"https://github.com/anntzer","@type":"Person","name":"anntzer"},"datePublished":"2018-10-29T18:31:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/12665/matplotlib/issues/12665"}
| 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:6b2e397a-3d28-8d5b-d070-3594138b6941 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AAEA:306788:3B546F:4ECCE9:6A529160 |
| html-safe-nonce | 16d44f632d9c0207c497f609aff95c7763dd89003026b832abfe6b7b7675491a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUVBOjMwNjc4ODozQjU0NkY6NEVDQ0U5OjZBNTI5MTYwIiwidmlzaXRvcl9pZCI6IjQ2OTYxMjMyNzc2NTkyNDY5NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 425d82a0680d37b89330ff551a57e02a21525aceb959093cc8214fe2fb45d4f6 |
| hovercard-subject-tag | issue:375157533 |
| 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/12665/issue_layout |
| twitter:image | https://opengraph.githubassets.com/65ddbbbd9faf61db4e872c22b5ed2db457dcbb65b4e5b1ef0e4e79a30e027e1e/matplotlib/matplotlib/issues/12665 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/65ddbbbd9faf61db4e872c22b5ed2db457dcbb65b4e5b1ef0e4e79a30e027e1e/matplotlib/matplotlib/issues/12665 |
| og:image:alt | Bug report Bug summary When using a decreasing Norm, colorbars show no ticks. Code for reproduction This example uses a PowerNorm-like norm which first applies the power, then does linear rescaling... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anntzer |
| 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