8000 FIX: Only send one update signal when autoscaling norms · matplotlib/matplotlib@bad5973 · GitHub
[go: up one dir, main page]

Skip to content

Commit bad5973

Browse files
committed
FIX: Only send one update signal when autoscaling norms
Signal are sent for every vmin/vmax update, when autoscaling we were changing vmin/vmax to None, then updating them which would cause 4 update signals to be sent. We really don't care about the intermediate signals and only want a single one sent after all the udpates are complete.
1 parent 66f7956 commit bad5973

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/matplotlib/colors.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,8 +1362,12 @@ def inverse(self, value):
13621362

13631363
def autoscale(self, A):
13641364
"""Set *vmin*, *vmax* to min, max of *A*."""
1365-
self.vmin = self.vmax = None
1366-
self.autoscale_None(A)
1365+
with self.callbacks.blocked():
1366+
# Pause callbacks while we are updating so we only get
1367+
# a single update signal at the end
1368+
self.vmin = self.vmax = None
1369+
self.autoscale_None(A)
1370+
self._changed()
13671371

13681372
def autoscale_None(self, A):
13691373
"""If vmin or vmax are not set, use the min/max of *A* to set them."""

lib/matplotlib/tests/test_colors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,11 @@ def test_norm_callback():
14931493
norm.vmax = 5
14941494
assert increment.call_count == 2
14951495

1496+
# We only want autoscale() calls to send out one update signal
1497+
increment.call_count = 0
1498+
norm.autoscale([0, 1, 2])
1499+
assert increment.call_count == 1
1500+
14961501

14971502
def test_scalarmappable_norm_update():
14981503
norm = mcolors.Normalize()

0 commit comments

Comments
 (0)
0