File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1617,8 +1617,10 @@ def _fix_ipython_backend2gui(cls):
16171617 @contextmanager
16181618 def _idle_draw_cntx (self ):
16191619 self ._is_idle_drawing = True
1620- yield
1621- self ._is_idle_drawing = False
1620+ try :
1621+ yield
1622+ finally :
1623+ self ._is_idle_drawing = False
16221624
16231625 def is_saving (self ):
16241626 """
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -565,8 +565,15 @@ def _auto_draw_if_interactive(fig, val):
565565 fig : Figure
566566 A figure object which is assumed to be associated with a canvas
567567 """
568- if val and matplotlib .is_interactive () and not fig .canvas .is_saving ():
569- fig .canvas .draw_idle ()
568+ if (val and matplotlib .is_interactive ()
569+ and not fig .canvas .is_saving ()
570+ and not fig .canvas ._is_idle_drawing ):
571+ # Some artists can mark themselves as stale in the middle of drawing
572+ # (e.g. axes position & tick labels being computed at draw time), but
573+ # this shouldn't trigger a redraw because the current redraw will
574+ # already take them into account.
575+ with fig .canvas ._idle_draw_cntx ():
576+ fig .canvas .draw_idle ()
570577
571578
572579def gcf ():
You can’t perform that action at this time.
0 commit comments