Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b18a576

Browse files
committed
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
1 parent 21ec4fc commit b18a576

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lib/matplotlib/backends/backend_gtk3agg.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def on_draw_event(self, widget, ctx):
2626
w, h = allocation.width, allocation.height
2727

2828
if not len(self._bbox_queue):
29-
self._render_figure(w, h)
3029
Gtk.render_background(
3130
self.get_style_context(), ctx,
3231
allocation.x, allocation.y,
@@ -71,6 +70,12 @@ def blit(self, bbox=None):
7170
self._bbox_queue.append(bbox)
7271
self.queue_draw_area(x, y, width, height)
7372

73+
def draw(self):
74+
if self.get_visible() and self.get_mapped():
75+
allocation = self.get_allocation()
76+
self._render_figure(allocation.width, allocation.height)
77+
super(FigureCanvasGTK3Agg).draw()
78+
7479
def print_png(self, filename, *args, **kwargs):
7580
# Do this so we can save the resolution of figure in the PNG file
7681
agg = self.switch_backends(backend_agg.FigureCanvasAgg)

0 commit comments

Comments
 (0)