Title: _make_norm_from_scale needs to process values · Issue #19239 · matplotlib/matplotlib · GitHub
Open Graph Title: _make_norm_from_scale needs to process values · Issue #19239 · matplotlib/matplotlib
X Title: _make_norm_from_scale needs to process values · Issue #19239 · matplotlib/matplotlib
Description: As noted in #18653, norms created via colors._make_norm_from_scale do not process values that are passed to inverse so norm.inverse([0.2, 5, 10]) fails, whereas norm.inverse(np.array([0.2, 5, 10])) works fine. @QuLogic noticed this: Prob...
Open Graph Description: As noted in #18653, norms created via colors._make_norm_from_scale do not process values that are passed to inverse so norm.inverse([0.2, 5, 10]) fails, whereas norm.inverse(np.array([0.2, 5, 10]))...
X Description: As noted in #18653, norms created via colors._make_norm_from_scale do not process values that are passed to inverse so norm.inverse([0.2, 5, 10]) fails, whereas norm.inverse(np.array([0.2, 5, 10]))...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/19239
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"_make_norm_from_scale needs to process values","articleBody":"As noted in #18653, norms created via `colors._make_norm_from_scale` do not process values that are passed to `inverse` so `norm.inverse([0.2, 5, 10])` fails, whereas `norm.inverse(np.array([0.2, 5, 10]))` works fine. \r\n\r\n@QuLogic noticed this: \r\n\r\nProbably because `inverse` doesn't pass `value` through `process_value` like `__call__` does. Something like:\r\n```diff\r\ndiff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py\r\nindex e417b8178d..b37ec947fa 100644\r\n--- a/lib/matplotlib/colors.py\r\n+++ b/lib/matplotlib/colors.py\r\n@@ -1449,12 +1449,14 @@ def _make_norm_from_scale(scale_cls, base_norm_cls=None, *, init=None):\r\n t_vmin, t_vmax = self._trf.transform([self.vmin, self.vmax])\r\n if not np.isfinite([t_vmin, t_vmax]).all():\r\n raise ValueError(\"Invalid vmin or vmax\")\r\n+ value, is_scalar = self.process_value(value)\r\n rescaled = value * (t_vmax - t_vmin)\r\n rescaled += t_vmin\r\n- return (self._trf\r\n- .inverted()\r\n- .transform(rescaled)\r\n- .reshape(np.shape(value)))\r\n+ t_value = (self._trf\r\n+ .inverted()\r\n+ .transform(rescaled)\r\n+ .reshape(np.shape(value)))\r\n+ return t_value[0] if is_scalar else t_value\r\n \r\n Norm.__name__ = base_norm_cls.__name__\r\n Norm.__qualname__ = base_norm_cls.__qualname__\r\n```\r\nMaybe it also needs the masking?\r\n\r\n_Originally posted by @QuLogic in https://github.com/matplotlib/matplotlib/pull/18653#discussion_r551657752_\r\n\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/jklymak","@type":"Person","name":"jklymak"},"datePublished":"2021-01-05T01:33:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/19239/matplotlib/issues/19239"}
| 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:0261e153-b797-e1ae-aacc-b65c9ecc540a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95C8:2CAF25:2D05CB:3B7E34:6A52CADA |
| html-safe-nonce | dc2ad15830ae9843e934d5638372228f87d7ef48ee93246beefb8d0d3b161971 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUM4OjJDQUYyNToyRDA1Q0I6M0I3RTM0OjZBNTJDQURBIiwidmlzaXRvcl9pZCI6IjMxMTI3MzIyNTA1Mzk3Mzk4NjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b7beae9af73ad642276788f48f0c70c9df61e0a418828e948568a46c9d801610 |
| hovercard-subject-tag | issue:778497965 |
| 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/19239/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5207cde083c15cb9ac0c6a4814c4fa236ad705fc9c77848ec9d4828034cd0717/matplotlib/matplotlib/issues/19239 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5207cde083c15cb9ac0c6a4814c4fa236ad705fc9c77848ec9d4828034cd0717/matplotlib/matplotlib/issues/19239 |
| og:image:alt | As noted in #18653, norms created via colors._make_norm_from_scale do not process values that are passed to inverse so norm.inverse([0.2, 5, 10]) fails, whereas norm.inverse(np.array([0.2, 5, 10]))... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jklymak |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width