File tree Expand file tree Collapse file tree 3 files changed +24
-14
lines changed
Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Original file line number Diff line number Diff 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 """
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
592599def gcf ():
You can’t perform that action at this time.
0 commit comments