Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Wrong behavior of blitting in Gtk3Agg backend #1575

spinnau opened this Issue · 2 comments

2 participants


The blitting in the Gtk3Agg backend will not work properly (mpl 1.2.0, Gtk 3.6.2, Python 2.7.3). Redrawing is done for the entire canvas, but only a part of the canvas area is used as a background image. Thus, some regions only shows white or grey space instead of their original content.

This can easily be reproduced with the matplotlib rectangle_selector example. If used with backend set to GtkAgg in matplotlibrc file, then all will be fine. With backend set to Gtk3Agg, only content of the axes is shown. The background of the figure together with the axes ticks and labels will be missed during blitting.

The reason is that the FigureCanvasGTK3Agg.blit() method in invokes the queue_draw() method of the Gtk widget, which redraws the entire area of the widget. Instead the queue_draw_area() method should be used.

After applying the following patch to the backend has the desired behavior:

---  2012-11-29 15:18:34.000000000 +0100
+++  2012-12-08 13:14:33.729618000 +0100
@@ -59,8 +59,21 @@
         return False
     def blit(self, bbox=None):
+        # If bbox is None, blit the entire canvas to gtk. Otherwise
+        # blit only the area defined by the bbox.
+        if bbox is None:
+            bbox = self.figure.bbox
+        allocation = self.get_allocation()
+        w, h = allocation.width, allocation.height
+        x = int(bbox.x0)
+        y = h - int(bbox.y1)
+        width = int(bbox.x1) - int(bbox.x0)
+        height = int(bbox.y1) - int(bbox.y0)
-        self.queue_draw()
+        self.queue_draw_area(x, y, width, height)
     def print_png(self, filename, *args, **kwargs):
         # Do this so we can save the resolution of figure in the PNG file

Thanks for all the nice work to get the new Gtk3 backends available,



@spinnau Thank you for tracking this down and providing a fix. Would you be willing to take the next step, and make a Pull Request against v1.2.x for this? Your patch is fixing a substantial bug, so it should go in v1.2.x, not master.


@efiring Ok, i have created a Pull Request for the patch.

@spinnau spinnau closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.