New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clipping for OffsetBoxes #4466
Merged
Merged
Clipping for OffsetBoxes #4466
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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' respects 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 on a per-child basis using `child.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` can be | ||
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, clip=True) | ||
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) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super picky, extra space between 'be' and 'clipped'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will take care of this. I want to extend this PR a bit and will just do it my self rather than explain what I want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I rebased and pushed already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it looks like I won the race condition on that and merged the previous version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if you have a change set, please open a PR.
On Mon, May 25, 2015 at 11:25 PM Hassan Kibirige notifications@github.com
wrote: