8000 FIX: add check if the renderer exists · matplotlib/matplotlib@83150d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 83150d7

Browse files
committed
FIX: add check if the renderer exists
There exists a path where paintEvent can be called before the first time that `draw` has been called. This results in an exception because the call to `FigureCanvasAgg.draw(self)` is what create the renderer attribute on the canvas.
1 parent b9bc7d1 commit 83150d7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ def paintEvent(self, e):
7575
In Qt, all drawing should be done inside of here when a widget is
7676
shown onscreen.
7777
"""
78-
# FigureCanvasQT.paintEvent(self, e)
78+
# if the canvas does not have a renderer, then
79+
# FigureCanvasAgg.draw(self) has never been called so force it to
80+
# be called to create the renderer and to render the initial view
81+
# of the figure
82+
if not hasattr(self, 'renderer'):
83+
FigureCanvasAgg.draw(self)
84+
7985
if DEBUG:
8086
print('FigureCanvasQtAgg.paintEvent: ', self,
8187
self.get_width_height())

0 commit comments

Comments
 (0)
0