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

Fix twoslopenorm colorbar#20582

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
QuLogic merged 2 commits intomatplotlib:masterfromjklymak:fix-twoslopenorm-colorbar
Jul 13, 2021

Conversation

jklymak
Copy link
Member

PR Summary

Closes#20581

#20054 makes it so the scale on a colorbar is set via the norm, and the inverse of its norm. The problem with scales, and tickers, is that they seek ticks beyond the min/max of their axis. PreviouslyTwoSlopeNorm linearly interpolated between vmin and vcenter and vcenter and vmax, but anything beyond vmax or less than vmin was also mapped to 0 and 1. So in the broken example a tick was sought at -1000, with vmin =-500. The norm processed this as 0 instead of a negative number, and hence it showed up on the axis.

Here we fix that by simply doing some linear extrapolation on the TwoSlopeNorm and its inverse.np.interp doesn't have linear extrapolation by default, and we can't use scipy, so just do it by hand. (yes I know thatvcenter - 2 * (vcenter - vmin) = 2 * vmin - vcenter, but that is not as easy to parse).

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 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).

@jklymakjklymak added Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: color/colorbar topic: color/color & colormaps labelsJul 6, 2021
@jklymakjklymak added this to thev3.5.0 milestoneJul 6, 2021
@jklymakjklymakforce-pushed thefix-twoslopenorm-colorbar branch frombd4102c to78ddee0CompareJuly 6, 2021 15:46
@QuLogic
Copy link
Member

(yes I know thatvcenter - 2 * (vcenter - vmin) = 2 * vmin - vcenter, but that is not as easy to parse).

You could also write thatvmin - (vcenter - vmin), which is not as simplified, but maybe still easy to parse?

jklymak reacted with thumbs up emoji

@jklymakjklymakforce-pushed thefix-twoslopenorm-colorbar branch from78ddee0 to9ef1caaCompareJuly 7, 2021 13:56
@greglucas
Copy link
Contributor

As a general question, do you actually want to add extrapolation to these functions, or should we just set the left/right bounds to -inf/+inf to not make any assumptions beyond the data interval?

np.interp([self.vmin,self.vcenter,self.vmax], [0,0.5,1],left=-np.inf,right=np.inf)
jklymak reacted with thumbs up emoji

@jklymakjklymakforce-pushed thefix-twoslopenorm-colorbar branch from266eac6 toa2f5a77CompareJuly 7, 2021 21:12
@jklymak
Copy link
MemberAuthor

@greglucas Yep, you are right, that works as well and is more elegant.

@jklymakjklymakforce-pushed thefix-twoslopenorm-colorbar branch froma2f5a77 to38ad08eCompareJuly 7, 2021 21:14
Comment on lines +316 to +317
# defining your own norm. Note for the colorbar to work, you must
# define an inverse for your norm:
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it would make sense to create an abstract base class for Norms that raisesNotImplemented forinverse() so that it doesn't accidentally work with a colorbar? (I think right now it is inheriting the inverse from the standard "Linear"Normalize class. We could catch theNotImplemented in the Colorbar code and warn appropriately there that the inverse method needs to be implemented.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think that would be sensible.

Copy link
Member

Choose a reason for hiding this comment

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

#7320 seems related to that.

@QuLogic
Copy link
Member

I feel like the custom norm example never intended the 0 to be in the middle; maybe it needs to be written another way?

@jklymak
Copy link
MemberAuthor

I wrote that example and indeed it's pretty common for water depths to have a different vertical scale than land relief.

If you want the size of the color ranges to be proportionate you would make the color map disproportionate with more land colours than ocean colours. But that is the opposite of the desired effect here.

@QuLogic
Copy link
Member

Ah, I see that was mentioned in theTwoSlopeNorm section, but not the custom norm one. Perhaps that could be re-iterated there? As I just skipped directly to that section without reading the rest and didn't know it was intentional that way.

@jklymak
Copy link
MemberAuthor

The first sentence of the example says that it is the same as the TwoSlopeNorm example?

@QuLogic
Copy link
Member

Or I'm just blind today...

jklymak reacted with laugh emoji

@QuLogicQuLogic merged commit1df0529 intomatplotlib:masterJul 13, 2021
@jklymakjklymak deleted the fix-twoslopenorm-colorbar branchJuly 13, 2021 05:00
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic approved these changes

@greglucasgreglucasgreglucas approved these changes

Assignees
No one assigned
Labels
Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.topic: color/color & colormapstopic: color/colorbar
Projects
None yet
Milestone
v3.5.0
Development

Successfully merging this pull request may close these issues.

Change in custom norm colour map display
3 participants
@jklymak@QuLogic@greglucas

[8]ページ先頭

©2009-2025 Movatter.jp