Skip to content


Subversion checkout URL

You can clone with
Download ZIP


text is not properly clipped in 1.2.1 #1885

merged 1 commit into from

3 participants


matplotlib 1.2.1, python 2.7.3, OS X 10.8.3, TkAgg backend

Calling text() to render and then interactively panning the image, the resulting text is not properly clipped to the data window, and over flows it.

Code to reproduce:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

t1 = ax.text(0.5, 0.2, 'no clip')
t2 = ax.text(0.5, 0.3, 'clipped', clip_on=True)

Now pan the text to the data window borders and watch the clipping.

Possible resolution:
So the bug appears to be that the initial bounding box for text is not set if 'clip_on' is not supplied as an arg.

t1.get_clip_on() == True
t1.get_clip_box() == None
t2.get_clip_on() == True
t2.get_clip_box() == TransformedBbox(...)

Toggling clip_on does not fix the problem.


I can confirm this on python 2.7.4rc1, mpl 1.3.x, linux, Qt4Agg backend

@mdboom mdboom Fix #1885: Text clipping should always set the patch to the axes, reg…
…ardless of the state of the clip_on kwarg, so that clip_on can be toggled after the fact

Confirmed. This is inconsistent with how other artists are handled -- they generally have the clip path assigned to them regardless of whether the clip is on or not so that it can later be toggled. I think the intent here is that text, unlike most other artists, defaults to having no clipping (which makes sense, since it's usually an axis label or an annotation, which one would not want to be clipped). However, since the clip path never gets set, it can't (easily) be turned on later.

Interestingly, this behavior goes way back in the annals of time to at least 909f34b (in 2007). @efiring: as another "old timer" here, do you know why it may have been implemented this way, or do you think this was probably just an easy-to-make bug due to the fact that text is not clipped by default?


The tests are failing trying to install inkscape -- I don't know if that's just transient or Travis no longer makes this work. @pelson, #1869

@mdboom mdboom merged commit 41315b6 into matplotlib:v1.2.x
@mdboom mdboom deleted the mdboom:clip-text branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2013
  1. @mdboom

    Fix #1885: Text clipping should always set the patch to the axes, reg…

    mdboom authored
    …ardless of the state of the clip_on kwarg, so that clip_on can be toggled after the fact
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 3 deletions.
  1. +2 −3 lib/matplotlib/
5 lib/matplotlib/
@@ -3394,6 +3394,7 @@ def text(self, x, y, s, fontdict=None,
'verticalalignment' : 'baseline',
'horizontalalignment' : 'left',
'transform' : self.transData,
+ 'clip_on' : False
# At some point if we feel confident that TextWithDash
@@ -3418,9 +3419,7 @@ def text(self, x, y, s, fontdict=None,
t._remove_method = lambda h: self.texts.remove(h)
- #if t.get_clip_on(): t.set_clip_box(self.bbox)
- if 'clip_on' in kwargs: t.set_clip_box(self.bbox)
+ t.set_clip_path(self.patch)
return t
Something went wrong with that request. Please try again.