-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
boundarynorm fix #7553
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
boundarynorm fix #7553
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0a288a2
Update utils.py
veenstrajelmer 3d84b2c
Update test_plot.py
veenstrajelmer c9e4a41
Merge pull request #1 from veenstrajelmer/patch-1
veenstrajelmer 4effc03
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c2ce3c1
fix as suggested by jklymak
veenstrajelmer 9bbc690
Merge branch 'main' into patch-2
veenstrajelmer 1c764c2
updated testcase
veenstrajelmer 3a60f1d
enabled type checking of test_discrete_colormap_provided_boundary_nor…
veenstrajelmer 317cab8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5b5335d
updated whats-new.rst
veenstrajelmer 35ed8d1
Merge branch 'patch-2' of https://github.com/veenstrajelmer/xarray in…
veenstrajelmer b6d6cb1
enabled type checking of test_discrete_colormap_provided_boundary_nor…
veenstrajelmer a1c0391
Merge branch 'main' into patch-2
veenstrajelmer 45eaf42
Merge branch 'patch-2' of https://github.com/veenstrajelmer/xarray in…
veenstrajelmer e7306a0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4dfb3ac
Update doc/whats-new.rst
veenstrajelmer 0936a66
Merge branch 'main' into patch-2
veenstrajelmer b3a7c4a
moved whatsnew for pull 7553 to 2023.04 section
veenstrajelmer bdaf380
Merge branch 'main' into patch-2
veenstrajelmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is some incompatibility between "levels" and "BoundaryNorm" - you really shouldn't use both and there should be no need to discretize the colormap if using a BoundaryNorm; conversely, there is no need to use a BoundaryNorm or discretize the colormap if using "levels" in a contour plot.
I'm not fully familiar with the xarray pcolormesh API, but I would raise if the user passes both BoundaryNorm and "levels", as having incompatible or duplicated specifications of the color boundaries, and I wouldn't do anything if a BoundaryNorm is passed in. If you want discrete colormaps with levels, but a non-linear norm, I think
_build_discrete_cmap
is fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your valuable feedback. I see your point and I agree, since the "levels" can be derived from BoundaryNorm.vmin, BoundaryNorm.vmax and BoundaryNorm.N. I also considered your alternative suggestion and issues #4061 and Deltares/xugrid#49 are indeed fixed by supplying
levels
instead ofnorm
tods.plot()
.However, if it is not beneficial to supply norm=BoundaryNorm to ds.plot(), I would say it should raise an error instead of being incorrectly catched in an if-statement. Would you agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jklymak: could you let me know if you agree. If so, I will make a separate issue and close this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming we are talking about
pcolormesh
, Matplotlib has no levels kwarg, so it's a bit strange for xarray to have grown one. I would not prohibit the Matplotlib way of doing this (BoundaryNorm
). If you want to keep the convenience of levels, then I would just error if both levels andBoundaryNorm
are passed.In either case, I'm not clear why folks are using levels at all for a pcolormesh, but that is just me ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jklymak, the issue here is that levels is constructed by xarray, it is not passed by the user. The user passes the norm argument only (#4061 by @rjp23). The result is a mismatch in length of Ncolors in the cmap and the amount of levels in the BoundaryNorm object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is a BoundaryNorm already, I'm not following why you are wanting to build a discrete cmap - the norm will discretize the underlying cmap for you...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jklymak You can ignore the PR I did, this is a workaround for the issue in #4061, but as I have learned from you it is not an improvement for xarray. The issue I am referring to provides the norm argument upon plotting, but it behaves different than the matplotlib. I do not understand the xarray plotting code good enough to provide a proper fix for this issue since it is a bit complex. As far as I understand, this PR can be closed without merging, but the issue is not fixed yet. Maybe you can suggest a proper fix for the code in the issue? You seem to understand how the plotting methods should behave.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR is very close, just you went the opposite way with it. I think it should actually be
and not create a colormap if BoundaryNorm is being used....