|
2 | 2 | unicode_literals)
|
3 | 3 |
|
4 | 4 | import nose
|
5 |
| - |
6 |
| -from matplotlib.testing.decorators import image_comparison |
| 5 | +from nose.tools import assert_true, assert_false |
| 6 | +from matplotlib.testing.decorators import image_comparison, cleanup |
7 | 7 | import matplotlib.pyplot as plt
|
8 | 8 | import matplotlib.patches as mpatches
|
9 | 9 | import matplotlib.lines as mlines
|
@@ -45,5 +45,42 @@ def test_offsetbox_clipping():
|
45 | 45 | ax.set_ylim((0, 1))
|
46 | 46 |
|
47 | 47 |
|
| 48 | +@cleanup |
| 49 | +def test_offsetbox_clip_children(): |
| 50 | + # - create a plot |
| 51 | + # - put an AnchoredOffsetbox with a child DrawingArea |
| 52 | + # at the center of the axes |
| 53 | + # - give the DrawingArea a gray background |
| 54 | + # - put a black line across the bounds of the DrawingArea |
| 55 | + # - see that the black line is clipped to the edges of |
| 56 | + # the DrawingArea. |
| 57 | + fig, ax = plt.subplots() |
| 58 | + size = 100 |
| 59 | + da = DrawingArea(size, size, clip=True) |
| 60 | + bg = mpatches.Rectangle((0, 0), size, size, |
| 61 | + facecolor='#CCCCCC', |
| 62 | + edgecolor='None', |
| 63 | + linewidth=0) |
| 64 | + line = mlines.Line2D([-size*.5, size*1.5], [size/2, size/2], |
| 65 | + color='black', |
| 66 | + linewidth=10) |
| 67 | + anchored_box = AnchoredOffsetbox( |
| 68 | + loc=10, |
| 69 | + child=da, |
| 70 | + pad=0., |
| 71 | + frameon=False, |
| 72 | + bbox_to_anchor=(.5, .5), |
| 73 | + bbox_transform=ax.transAxes, |
| 74 | + borderpad=0.) |
| 75 | + |
| 76 | + da.add_artist(bg) |
| 77 | + da.add_artist(line) |
| 78 | + ax.add_artist(anchored_box) |
| 79 | + |
| 80 | + fig.canvas.draw() |
| 81 | + assert_false(fig.stale) |
| 82 | + da.clip_children = True |
| 83 | + assert_true(fig.stale) |
| 84 | + |
48 | 85 | if __name__ == '__main__':
|
49 | 86 | nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
|
0 commit comments