Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Child `Artists` of `DrawingArea` now get clipped to the bounds of the parent
- Loading branch information
Showing
9 changed files
with
329 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'OffsetBox.DrawingArea' no longer accepts the 'clip' keyword argument | ||
````````````````````````````````````````````````````````````````````` | ||
|
||
The call signature was `OffsetBox.DrawingArea(..., clip=True)` but nothing | ||
was done with the `clip` argument. The object did not do any clipping | ||
regardless of that parameter. Now the object can and does clip the child `Artists` if they are set to be clipped. | ||
|
||
You can turn off the clipping using :method:`Artist.set_clip_on(False)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
OffsetBoxes now support clipping | ||
```````````````````````````````` | ||
|
||
`Artists` draw onto objects of type :class:`~OffsetBox` | ||
through :class:`~OffsetBox.DrawingArea` and :class:`~OffsetBox.TextArea`. | ||
The `TextArea` calculates the required space for the text and so the | ||
text is always within the bounds, for this nothing has changed. | ||
|
||
However, `DrawingArea` acts as a parent for zero or more `Artists` that | ||
draw on it and may do so beyond the bounds. Now child `Artists` are by | ||
default clipped to the bounds of the `DrawingArea`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.55 KB
lib/matplotlib/tests/baseline_images/test_offsetbox/offsetbox_clipping.pdf
Binary file not shown.
Binary file added
BIN
+3.88 KB
lib/matplotlib/tests/baseline_images/test_offsetbox/offsetbox_clipping.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
241 changes: 241 additions & 0 deletions
241
lib/matplotlib/tests/baseline_images/test_offsetbox/offsetbox_clipping.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
|
||
import nose | ||
|
||
from matplotlib.testing.decorators import image_comparison | ||
import matplotlib.pyplot as plt | ||
import matplotlib.patches as mpatches | ||
import matplotlib.lines as mlines | ||
from matplotlib.offsetbox import AnchoredOffsetbox, DrawingArea | ||
|
||
|
||
@image_comparison(baseline_images=['offsetbox_clipping'], remove_text=True) | ||
def test_offsetbox_clipping(): | ||
# - create a plot | ||
# - put an AnchoredOffsetbox with a child DrawingArea | ||
# at the center of the axes | ||
# - give the DrawingArea a gray background | ||
# - put a black line across the bounds of the DrawingArea | ||
# - see that the black line is clipped to the edges of | ||
# the DrawingArea. | ||
fig, ax = plt.subplots() | ||
size = 100 | ||
da = DrawingArea(size, size) | ||
bg = mpatches.Rectangle((0, 0), size, size, | ||
facecolor='#CCCCCC', | ||
edgecolor='None', | ||
linewidth=0) | ||
line = mlines.Line2D([-size*.5, size*1.5], [size/2, size/2], | ||
color='black', | ||
linewidth=10) | ||
anchored_box = AnchoredOffsetbox( | ||
loc=10, | ||
child=da, | ||
pad=0., | ||
frameon=False, | ||
bbox_to_anchor=(.5, .5), | ||
bbox_transform=ax.transAxes, | ||
borderpad=0.) | ||
|
||
da.add_artist(bg) | ||
da.add_artist(line) | ||
ax.add_artist(anchored_box) | ||
ax.set_xlim((0, 1)) | ||
ax.set_ylim((0, 1)) | ||
|
||
|
||
if __name__ == '__main__': | ||
nose.runmodule(argv=['-s', '--with-doctest'], exit=False) |