text is not properly clipped in 1.2.1 #1885

merged 1 commit into from May 13, 2013


None yet
2 participants

mdboom commented Apr 8, 2013

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.


tacaswell commented Apr 6, 2013

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

mdboom commented Apr 8, 2013

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?


mdboom commented Apr 8, 2013

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 added a commit that referenced this pull request May 13, 2013

@mdboom mdboom Merge pull request #1885 from mdboom/clip-text
text is not properly clipped in 1.2.1

@mdboom mdboom merged commit 41315b6 into matplotlib:v1.2.x May 13, 2013

1 check failed

default The Travis CI build could not complete due to an error

mdboom deleted the mdboom:clip-text branch Aug 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment