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

ENH: Add func norm#18653

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

Merged
jklymak merged 1 commit intomatplotlib:masterfromjklymak:enh-add-func-norm
Jan 15, 2021
Merged

Conversation

jklymak
Copy link
Member

@jklymakjklymak commentedOct 4, 2020
edited
Loading

PR Summary

Derives a func norm from func scale. From the example:

################################################################################ FuncNorm: Arbitrary function normalization# ------------------------------------------## If the above norms do not provide the normalization you want, and you# can express your normalization in terms of function, you can use# `~.colors.FuncNorm`.  Note that this example is the same as# `PowerNorm` with a power of 0.5:def_forward(x):returnnp.sqrt(x)def_inverse(x):returnx**2N=100X,Y=np.mgrid[0:3:complex(0,N),0:2:complex(0,N)]Z1= (1+np.sin(Y*10.))*X**2fig,ax=plt.subplots()norm=colors.FuncNorm((_forward,_inverse),vmin=0,vmax=20)pcm=ax.pcolormesh(X,Y,Z1,norm=norm,cmap='PuBu_r',shading='auto')ax.set_title('FuncNorm(x)')fig.colorbar(pcm,shrink=0.6)plt.show()

FuncNorm

PR Checklist

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (runflake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • Conforms to Matplotlib style conventions (installflake8-docstrings andpydocstyle<4 and runflake8 --docstring-convention=all).
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).

@jklymakjklymakforce-pushed theenh-add-func-norm branch 3 times, most recently from989c966 to15af903CompareDecember 20, 2020 03:40
@jklymakjklymak marked this pull request as ready for reviewDecember 20, 2020 03:42
@jklymakjklymak added this to thev3.4.0 milestoneDec 20, 2020
Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

Minor style comments.

return 10**x
norm = mcolors.FuncNorm((forward, inverse), vmin=0.1, vmax=10)
lognorm = mcolors.LogNorm(vmin=0.1, vmax=10)
assert_array_almost_equal(norm([0.2, 5, 10]), lognorm([0.2, 5, 10]))
Copy link
Member

Choose a reason for hiding this comment

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

Did you not want to assert the inverse here as well?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah I wasn't going to but it does drop our test coverage, so added...

Interestingly the_make_norm_from_scale inverse doesn't work on a list of floats (i.e. [1, 2, 3]), but only on a numpy array (np.array([1, 2, 3])) whereas the forward works on a bare list. Not sure if that is a bug.@anntzer ?

Copy link
Member

@QuLogicQuLogicJan 5, 2021
edited
Loading

Choose a reason for hiding this comment

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

Probably becauseinverse doesn't passvalue throughprocess_value like__call__ does. Something like:

diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.pyindex e417b8178d..b37ec947fa 100644--- a/lib/matplotlib/colors.py+++ b/lib/matplotlib/colors.py@@ -1449,12 +1449,14 @@ def _make_norm_from_scale(scale_cls, base_norm_cls=None, *, init=None):             t_vmin, t_vmax = self._trf.transform([self.vmin, self.vmax])             if not np.isfinite([t_vmin, t_vmax]).all():                 raise ValueError("Invalid vmin or vmax")+            value, is_scalar = self.process_value(value)             rescaled = value * (t_vmax - t_vmin)             rescaled += t_vmin-            return (self._trf-                    .inverted()-                    .transform(rescaled)-                    .reshape(np.shape(value)))+            t_value = (self._trf+                       .inverted()+                       .transform(rescaled)+                       .reshape(np.shape(value)))+            return t_value[0] if is_scalar else t_value      Norm.__name__ = base_norm_cls.__name__     Norm.__qualname__ = base_norm_cls.__qualname__

Maybe it also needs the masking?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Looks right. But maybe orthogonal to this PR. I opened an issue in#19239 just to keep them separate...

Copy link
Member

Choose a reason for hiding this comment

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

Since that is now fixed, do you want to remove thenp.array from the inverse check?

jklymak reacted with thumbs up emoji
@jklymak
Copy link
MemberAuthor

@timhoffm I think I addressed your concern above? Thanks!

Copy link
Member

@QuLogicQuLogic left a comment

Choose a reason for hiding this comment

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

Feel free to merge after.

return 10**x
norm = mcolors.FuncNorm((forward, inverse), vmin=0.1, vmax=10)
lognorm = mcolors.LogNorm(vmin=0.1, vmax=10)
assert_array_almost_equal(norm([0.2, 5, 10]), lognorm([0.2, 5, 10]))
Copy link
Member

Choose a reason for hiding this comment

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

Since that is now fixed, do you want to remove thenp.array from the inverse check?

jklymak reacted with thumbs up emoji
@jklymakjklymak merged commit6429e9d intomatplotlib:masterJan 15, 2021
@jklymakjklymak deleted the enh-add-func-norm branchJanuary 15, 2021 05:03
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.4.0
Development

Successfully merging this pull request may close these issues.

3 participants
@jklymak@QuLogic@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp