Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: Only send one update signal when autoscaling norms #25079

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 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,8 +1362,12 @@ def inverse(self, value):

def autoscale(self, A):
"""Set *vmin*, *vmax* to min, max of *A*."""
self.vmin = self.vmax = None
self.autoscale_None(A)
with self.callbacks.blocked():
# Pause callbacks while we are updating so we only get
# a single update signal at the end
self.vmin = self.vmax = None
self.autoscale_None(A)
Comment on lines +1365 to +1369
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just?

Suggested change
with self.callbacks.blocked():
# Pause callbacks while we are updating so we only get
# a single update signal at the end
self.vmin = self.vmax = None
self.autoscale_None(A)
if A.size():
self.vmin = A.min()
self.vmax = A.max()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

subclasses overwrite autoscale_None() to handle that themselves, so I think we need to defer to their implementations. I'd save that for another PR if someone wants to tackle it.

self._changed()

def autoscale_None(self, A):
"""If vmin or vmax are not set, use the min/max of *A* to set them."""
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,11 @@ def test_norm_callback():
norm.vmax = 5
assert increment.call_count == 2

# We only want autoscale() calls to send out one update signal
increment.call_count = 0
norm.autoscale([0, 1, 2])
assert increment.call_count == 1


def test_scalarmappable_norm_update():
norm = mcolors.Normalize()
Expand Down