8000 Merge pull request #16346 from meeseeksmachine/auto-backport-of-pr-16… · matplotlib/matplotlib@8e96621 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e96621

Browse files
authored
Merge pull request #16346 from meeseeksmachine/auto-backport-of-pr-16298-on-v3.2.x
Backport PR #16298 on branch v3.2.x (Don't recursively call draw_idle when updating artists at draw time.)
2 parents e09983a + e90e8ec commit 8e96621

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,8 +1652,10 @@ def _fix_ipython_backend2gui(cls):
16521652
@contextmanager
16531653
def _idle_draw_cntx(self):
16541654
self._is_idle_drawing = True
1655-
yield
1656-
self._is_idle_drawing = False
1655+
try:
1656+
yield
1657+
finally:
1658+
self._is_idle_drawing = False
16571659

16581660
def is_saving(self):
16591661
"""

lib/matplotlib/backends/backend_qt5.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -481,16 +481,17 @@ def draw_idle(self):
481481
QtCore.QTimer.singleShot(0, self._draw_idle)
482482

483483
def _draw_idle(self):
484-
if not self._draw_pending:
485-
return
486-
self._draw_pending = False
487-
if self.height() < 0 or self.width() < 0:
488-
return
489-
try:
490-
self.draw()
491-
except Exception:
492-
# Uncaught exceptions are fatal for PyQt5, so catch them instead.
493-
traceback.print_exc()
484+
with self._idle_draw_cntx():
485+
if not self._draw_pending:
486+
return
487+
self._draw_pending = False
488+
if self.height() < 0 or self.width() < 0:
489+
return
490+
try:
491+
self.draw()
492+
except Exception:
493+
# Uncaught exceptions are fatal for PyQt5, so catch them.
494+
traceback.print_exc()
494495

495496
def drawRectangle(self, rect):
496497
# Draw the zoom rectangle to the QPainter. _draw_rect_callback needs

lib/matplotlib/pyplot.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,15 @@ def _auto_draw_if_interactive(fig, val):
586586
fig : Figure
587587
A figure object which is assumed to be associated with a canvas
588588
"""
589-
if val and matplotlib.is_interactive() and not fig.canvas.is_saving():
590-
fig.canvas.draw_idle()
589+
if (val and matplotlib.is_interactive()
590+
and not fig.canvas.is_saving()
591+
and not fig.canvas._is_idle_drawing):
592+
# Some artists can mark themselves as stale in the middle of drawing
593+
# (e.g. axes position & tick labels being computed at draw time), but
594+
# this shouldn't trigger a redraw because the current redraw will
595+
# already take them into account.
596+
with fig.canvas._idle_draw_cntx():
597+
fig.canvas.draw_idle()
591598

592599

593600
def gcf():

0 commit comments

Comments
 (0)
0