Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1444745

Browse filesBrowse files
committed
Merge pull request #4473 from tacaswell/enh_offsetbox_clip_children
ENH: property if DrawingArea clips children
2 parents 1cfdc2e + 37b55b9 commit 1444745
Copy full SHA for 1444745

File tree

Expand file treeCollapse file tree

2 files changed

+53
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+53
-3
lines changed

‎lib/matplotlib/offsetbox.py

Copy file name to clipboardExpand all lines: lib/matplotlib/offsetbox.py
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ class DrawingArea(OffsetBox):
570570
"""
571571
The DrawingArea can contain any Artist as a child. The DrawingArea
572572
has a fixed width and height. The position of children relative to
573-
the parent is fixed. The children can be clipped at the
573+
the parent is fixed. The children can be clipped at the
574574
boundaries of the parent.
575575
"""
576576

@@ -596,6 +596,19 @@ def __init__(self, width, height, xdescent=0.,
596596

597597
self.dpi_transform = mtransforms.Affine2D()
598598

599+
@property
600+
def clip_children(self):
601+
"""
602+
If the children of this DrawingArea should be clipped
603+
by DrawingArea bounding box.
604+
"""
605+
return self._clip_children
606+
607+
@clip_children.setter
608+
def clip_children(self, val):
609+
self._clip_children = bool(val)
610+
self.stale = True
611+
599612
def get_transform(self):
600613
"""
601614
Return the :class:`~matplotlib.transforms.Transform` applied

‎lib/matplotlib/tests/test_offsetbox.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_offsetbox.py
+39-2Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
unicode_literals)
33

44
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
77
import matplotlib.pyplot as plt
88
import matplotlib.patches as mpatches
99
import matplotlib.lines as mlines
@@ -45,5 +45,42 @@ def test_offsetbox_clipping():
4545
ax.set_ylim((0, 1))
4646

4747

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+
4885
if __name__ == '__main__':
4986
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.