Skip to content

Commit e49d05a

Browse files
committed
Blocked set_clim() callbacks to prevent inconsistent state (#29522)
1 parent 24bb51c commit e49d05a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/matplotlib/colorizer.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,24 @@ def set_clim(self, vmin=None, vmax=None):
261261
.. ACCEPTS: (vmin: float, vmax: float)
262262
"""
263263
# If the norm's limits are updated self.changed() will be called
264-
# through the callbacks attached to the norm
264+
# through the callbacks attached to the norm, this causes an inconsistent
265+
# state, to prevent this blocked context manager is used
265266
if vmax is None:
266267
try:
267268
vmin, vmax = vmin
268269
except (TypeError, ValueError):
269270
pass
270-
if vmin is not None:
271-
self.norm.vmin = colors._sanitize_extrema(vmin)
272-
if vmax is not None:
273-
self.norm.vmax = colors._sanitize_extrema(vmax)
271+
272+
# Blocked context manager prevents callbacks from being triggered
273+
# until both vmin and vmax are updated
274+
with self.norm.callbacks.blocked(signal='changed'):
275+
if vmin is not None:
276+
self.norm.vmin = colors._sanitize_extrema(vmin)
277+
if vmax is not None:
278+
self.norm.vmax = colors._sanitize_extrema(vmax)
279+
280+
# self.changed() will now emit a update signal after both the limits are set
281+
self.changed()
274282

275283
def get_clim(self):
276284
"""

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy