diff --git a/lib/matplotlib/backends/backend_gdk.py b/lib/matplotlib/backends/backend_gdk.py index a67ab23a008b..33529d6cb2b3 100644 --- a/lib/matplotlib/backends/backend_gdk.py +++ b/lib/matplotlib/backends/backend_gdk.py @@ -142,7 +142,7 @@ def draw_image(self, gc, x, y, im): def draw_text(self, gc, x, y, s, prop, angle, ismath): x, y = int(x), int(y) - if x <0 or y <0: # window has shrunk and text is off the edge + if x < 0 or y < 0: # window has shrunk and text is off the edge return if angle not in (0,90): @@ -157,6 +157,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath): else: layout, inkRect, logicalRect = self._get_pango_layout(s, prop) l, b, w, h = inkRect + if (x + w > self.width or y + h > self.height): + return + self.gdkDrawable.draw_layout(gc.gdkGC, x, y-h-b, layout) @@ -225,7 +228,8 @@ def _draw_rotated_text(self, gc, x, y, s, prop, angle): x = int(x-h) y = int(y-w) - if x < 0 or y < 0: # window has shrunk and text is off the edge + if (x < 0 or y < 0 or: # window has shrunk and text is off the edge + x + w > self.width or y + h > self.height): return key = (x,y,s,angle,hash(prop))