From b18a576477e79f6ad3ac8200b8138cbdd91c5474 Mon Sep 17 00:00:00 2001 From: Ildar Akhmetgaleev Date: Thu, 6 Sep 2018 01:02:44 +0000 Subject: [PATCH 1/2] Speed up canvas redraw for GTK3Agg backend. Move `_render_figure()` call out of `on_draw_event` handler in `FigureCanvasGTK3Agg` class and call it from overloaded `draw()` method. Fixes #12010 Gtk triggers `draw` event not only when actual plot redraw required but also when any another widget drawn over canvas. This makes application with embided plot unresponsive in cases when popover or popup menu are drawn over plot. You may try example provided in #12010. Moving actual plot redraw out of `on_draw_event()` makes GUI much more responsive. This changes tested with: * animation from examples/ directory * interacive pan and zoom * cursor widget with bliting * calling draw_idle() to update interactive chart --- lib/matplotlib/backends/backend_gtk3agg.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_gtk3agg.py b/lib/matplotlib/backends/backend_gtk3agg.py index be59670bb426..64855d711100 100644 --- a/lib/matplotlib/backends/backend_gtk3agg.py +++ b/lib/matplotlib/backends/backend_gtk3agg.py @@ -26,7 +26,6 @@ def on_draw_event(self, widget, ctx): w, h = allocation.width, allocation.height if not len(self._bbox_queue): - self._render_figure(w, h) Gtk.render_background( self.get_style_context(), ctx, allocation.x, allocation.y, @@ -71,6 +70,12 @@ def blit(self, bbox=None): self._bbox_queue.append(bbox) self.queue_draw_area(x, y, width, height) + def draw(self): + if self.get_visible() and self.get_mapped(): + allocation = self.get_allocation() + self._render_figure(allocation.width, allocation.height) + super(FigureCanvasGTK3Agg).draw() + def print_png(self, filename, *args, **kwargs): # Do this so we can save the resolution of figure in the PNG file agg = self.switch_backends(backend_agg.FigureCanvasAgg) From db3b74112ae309c52b17630aea70c361bf6181b3 Mon Sep 17 00:00:00 2001 From: Ildar Akhmetgaleev Date: Thu, 6 Sep 2018 03:02:44 +0000 Subject: [PATCH 2/2] Fix calling super().draw(). Fix for previous commit. --- lib/matplotlib/backends/backend_gtk3agg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_gtk3agg.py b/lib/matplotlib/backends/backend_gtk3agg.py index 64855d711100..8e5b991daf80 100644 --- a/lib/matplotlib/backends/backend_gtk3agg.py +++ b/lib/matplotlib/backends/backend_gtk3agg.py @@ -74,7 +74,7 @@ def draw(self): if self.get_visible() and self.get_mapped(): allocation = self.get_allocation() self._render_figure(allocation.width, allocation.height) - super(FigureCanvasGTK3Agg).draw() + super().draw() def print_png(self, filename, *args, **kwargs): # Do this so we can save the resolution of figure in the PNG file