File tree 3 files changed +24
-14
lines changed
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):
1640
1640
@contextmanager
1641
1641
def _idle_draw_cntx (self ):
1642
1642
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
1645
1647
1646
1648
def is_saving (self ):
1647
1649
"""
Original file line number Diff line number Diff line change @@ -498,16 +498,17 @@ def draw_idle(self):
498
498
QtCore .QTimer .singleShot (0 , self ._draw_idle )
499
499
500
500
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 ()
511
512
512
513
def drawRectangle (self , rect ):
513
514
# 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):
585
585
fig : Figure
586
586
A figure object which is assumed to be associated with a canvas
587
587
"""
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 ()
590
597
591
598
592
599
def gcf ():
You can’t perform that action at this time.
0 commit comments