Title: Creation of the Norm Protocol by trygvrad · Pull Request #30149 · matplotlib/matplotlib · GitHub
Open Graph Title: Creation of the Norm Protocol by trygvrad · Pull Request #30149 · matplotlib/matplotlib
X Title: Creation of the Norm Protocol by trygvrad · Pull Request #30149 · matplotlib/matplotlib
Description: This PR is a response to a discussion in the past weeks weekly developer meeting regarding the creation of a Norm protocol before the introduction of MultiNorm #29876 (comment) Prior to this PR there are no Protocols in matplotlib. This implementation uses @runtime_checkable so that Colorizer.set_norm() can check _api.check_isinstance((colors.Norm, str, None), norm=norm) Note that the error message if the class one attempts to use is missing a member, is just the standard wrong-type message, and does not tell you what member of the protocol is missing. @timhoffm @tacaswell @ksunden @story645 The implementation looks like this: @runtime_checkable class Norm(Protocol): @property def vmin(self): """Lower limit of the input data interval; maps to 0.""" ... @property def vmax(self): """Upper limit of the input data interval; maps to 1.""" ... @property def clip(self): """ Determines the behavior for mapping values outside the range ``[vmin, vmax]``. See the *clip* parameter in `.Normalize`. """ ... def _changed(self): """ Call this whenever the norm is changed to notify all the callback listeners to the 'changed' signal. """ ... def __call__(self, value, clip=None): """ Normalize the data and return the normalized data. Parameters ---------- value Data to normalize. clip : bool, optional See the description of the parameter *clip* in `.Normalize`. If ``None``, defaults to ``self.clip`` (which defaults to ``False``). Notes ----- If not already initialized, ``self.vmin`` and ``self.vmax`` are initialized using ``self.autoscale_None(value)``. """ ... def inverse(self, value): """ Maps the normalized value (i.e., index in the colormap) back to image data value. Parameters ---------- value Normalized value. """ ... def autoscale(self, A): """Set *vmin*, *vmax* to min, max of *A*.""" ... def autoscale_None(self, A): """If *vmin* or *vmax* are not set, use the min/max of *A* to set them.""" ... def scaled(self): """Return whether *vmin* and *vmax* are both set.""" ... and some of the docstrings will need to be updated to also allow for MultiNorm, but this can happen in the next PR. This requires a lot more than the bare minimum. I tested, and I can do a plt.imshow() with just __call__ and autoscale_None, but I get the feeling that it is desirable to lock it down more.
Open Graph Description: This PR is a response to a discussion in the past weeks weekly developer meeting regarding the creation of a Norm protocol before the introduction of MultiNorm #29876 (comment) Prior to this PR the...
X Description: This PR is a response to a discussion in the past weeks weekly developer meeting regarding the creation of a Norm protocol before the introduction of MultiNorm #29876 (comment) Prior to this PR the...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/30149
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:917d3b7c-e62e-09c8-73f5-f8b630cc31c7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B996:156C3A:1DE4CE:281ED4:6A51872F |
| html-safe-nonce | 1fe65f85e8e4317241797e2db97b3b8a1e64f3f308435d2b82c8801886a8580b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTk2OjE1NkMzQToxREU0Q0U6MjgxRUQ0OjZBNTE4NzJGIiwidmlzaXRvcl9pZCI6IjczMzQxNzk2NzA3NTYyNjM3MjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9540c04510fb59542f552a9e641ebe2ce54b0df67286f6a7f52f66b99094e7b3 |
| hovercard-subject-tag | pull_request:2573699383 |
| 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/30149/files |
| twitter:image | https://avatars.githubusercontent.com/u/2361452?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/2361452?s=400&v=4 |
| og:image:alt | This PR is a response to a discussion in the past weeks weekly developer meeting regarding the creation of a Norm protocol before the introduction of MultiNorm #29876 (comment) Prior to this PR the... |
| 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 | cb77a7b8b06cd86c243be33fd8e7922d70a9d243 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width