From fcdcbeeb5038e8c9bb2cb4156038850dabf5746b Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Wed, 25 Jan 2023 14:24:00 -0600 Subject: [PATCH] Backport PR #25079: FIX: Only send one update signal when autoscaling norms --- lib/matplotlib/colors.py | 8 ++++++-- lib/matplotlib/tests/test_colors.py | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index ab0d73c4b5fb..9c0725c8888a 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -1372,8 +1372,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) + self._changed() def autoscale_None(self, A): """If vmin or vmax are not set, use the min/max of *A* to set them.""" diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index a5809f0fa89f..e40796caa7cc 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -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()