Skip to content

Commit 8feb6d8

Browse files
committed
Avoid triggering full dpi change if it's unchanged.
This is essentially a revert of the `Text.get_window_extent` change to its dpi handling, but applies in _all_ cases. Depending on backend, we want to avoid this extraneous dpi change, because it can cause recursive event signals. For example, with GTK3, a resize will trigger its event loop, which eventually causes a re-draw. The re-draw would get to `Text.get_window_extent`, change the dpi (to the same value), and call `Figure.set_size_inches`, which would resize the window again. Depending on how much of the GTK event loop was processed, this may or may not trigger another draw, recursing again and again. Fixes matplotlib#16934.
1 parent e702edd commit 8feb6d8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ def _set_dpi(self, dpi, forward=True):
442442
forward : bool
443443
Passed on to `~.Figure.set_size_inches`
444444
"""
445+
if dpi == self._dpi:
446+
# We don't want to cause undue events in backends.
447+
return
445448
self._dpi = dpi
446449
self.dpi_scale_trans.clear().scale(dpi)
447450
w, h = self.get_size_inches()

0 commit comments

Comments
 (0)