Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Creation of the Norm Protocol#30149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
trygvrad wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromtrygvrad:norm_protocol

Conversation

trygvrad
Copy link
Contributor

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 thatColorizer.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_checkableclass 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 aplt.imshow() with just__call__ andautoscale_None, but I get the feeling that it is desirable to lock it down more.

classNorm(Protocol):
callbacks:cbook.CallbackRegistry
@property
defvmin(self)->float|None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Wouldn't we need something like this to support MultiNorm?

Suggested change
defvmin(self)->float|None: ...
defvmin(self)->float|ArrayLike|None: ...

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes,

My logic was to get this into main first, and then change this with the MultiNorm PR, but I guess it is easier if I do it here. I will try to find the time early next week.

Is this PR otherwise as you would expect?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@trygvrad@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp