From bad597320473df616b5ea64d4d96b02749896025 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Wed, 25 Jan 2023 08:16:19 -0700 Subject: [PATCH] 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. --- 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 f9e4dcbd6250..07f54c4fc02d 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -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) + 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 6c812529e104..8f85af8edd31 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()