From 16baab901ce0a45459bbc954e3a0dba79d89c919 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 13 Sep 2015 17:17:09 -0400 Subject: [PATCH] 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. --- lib/matplotlib/backends/backend_qt5agg.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_qt5agg.py b/lib/matplotlib/backends/backend_qt5agg.py index 7c110762eb9e..656c837e5e65 100644 --- a/lib/matplotlib/backends/backend_qt5agg.py +++ b/lib/matplotlib/backends/backend_qt5agg.py @@ -75,7 +75,11 @@ def paintEvent(self, e): In Qt, all drawing should be done inside of here when a widget is shown onscreen. """ - # FigureCanvasQT.paintEvent(self, e) + # if the canvas does not have a renderer, then give up and wait for + # FigureCanvasAgg.draw(self) to be called + if not hasattr(self, 'renderer'): + return + if DEBUG: print('FigureCanvasQtAgg.paintEvent: ', self, self.get_width_height())