Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 99dd33f

Browse files
authored
Merge pull request #16345 from meeseeksmachine/auto-backport-of-pr-16298-on-v3.1.x
Backport PR #16298 on branch v3.1.x (Don't recursively call draw_idle when updating artists at draw time.)
2 parents 0447ad4 + 12004ed commit 99dd33f

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
@@ -1640,8 +1640,10 @@ def _fix_ipython_backend2gui(cls):
16401640
@contextmanager
16411641
def _idle_draw_cntx(self):
16421642
self._is_idle_drawing = True
1643-
yield
1644-
self._is_idle_drawing = False
1643+
try:
1644+
yield
1645+
finally:
1646+
self._is_idle_drawing = False
16451647

16461648
def is_saving(self):
16471649
"""

lib/matplotlib/backends/backend_qt5.py

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

500500
def _draw_idle(self):
501-
if not self._draw_pending:
502-
return
503-
self._draw_pending = False
504-
if self.height() < 0 or self.width() < 0:
505-
return
506-
try:
507-
self.draw()
508-
except Exception:
509-
# Uncaught exceptions are fatal for PyQt5, so catch them instead.
510-
traceback.print_exc()
501+
with self._idle_draw_cntx():
502+
if not self._draw_pending:
503+
return
504+
self._draw_pending = False
505+
if self.height() < 0 or self.width() < 0:
506+
return
507+
try:
508+
self.draw()
509+
except Exception:
510+
# Uncaught exceptions are fatal for PyQt5, so catch them.
511+
traceback.print_exc()
511512

512513
def drawRectangle(self, rect):
513514
# 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
@@ -585,8 +585,15 @@ def _auto_draw_if_interactive(fig, val):
585585
fig : Figure
586586
A figure object which is assumed to be associated with a canvas
587587
"""
588-
if val and matplotlib.is_interactive() and not fig.canvas.is_saving():
589-
fig.canvas.draw_idle()
588+
if (val and matplotlib.is_interactive()
589+
and not fig.canvas.is_saving()
590+
and not fig.canvas._is_idle_drawing):
591+
# Some artists can mark themselves as stale in the middle of drawing
592+
# (e.g. axes position & tick labels being computed at draw time), but
593+
# this shouldn't trigger a redraw because the current redraw will
594+
# already take them into account.
595+
with fig.canvas._idle_draw_cntx():
596+
fig.canvas.draw_idle()
590597

591598

592599
def gcf():

0 commit comments

Comments
 (0)