Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Add fig.add_artist method#11234
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Add fig.add_artist method#11234
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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.
Looks great asside frm the small formatting issues! Thanks!
lib/matplotlib/figure.py Outdated
Add any :class:`~matplotlib.artist.Artist` to the figure. | ||
If the added artist has no transform set to it previously, its | ||
transform will be set to ``transFigure``. |
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.
figure.transFigure
?
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 think ideally this docstring would be numpydoc compliant. Most offigure.py
isnot, but can't hurt to make this new one compliant.
lib/matplotlib/figure.py Outdated
If the added artist has no transform set to it previously, its | ||
transform will be set to ``transFigure``. | ||
Use ``add_artist`` only in cases you really need to add an artist to |
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.
This has a lot of "only" and "most often". Note a big reason to do this is if you don't want the artist in the tighbbox of the axes. Maybe:
Usually artists are added to axes objects using :meth:matplotlib.axes.Axes.add_artist
, but use this method in the rare cases that adding directly to the figure is necessary.
9969fc4
tof1046f6
CompareIn case the added artist has no transform set previously, it will assume | ||
set it the figure transform (``fig.transFigure``). | ||
This new mathod may be useful for adding artists to figures without axes or to |
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.
method
fig.add_artist(circ) | ||
In case the added artist has no transform set previously, it will assume | ||
set it the figure transform (``fig.transFigure``). |
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.
Broken sentence
lib/matplotlib/figure.py Outdated
transform set to it previously, its transform will be set to | ||
``figure.transFigure``. | ||
clip : bool, optional, default ``False`` | ||
An optional parameter ``clip`` may be used to determine whether the |
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.
Shorter: „Determines whether ...“
f1046f6
toec6df1d
CompareIt doesn't seem like the failing test is due to anything commited here. |
ec6df1d
to2bdffec
CompareRebasing didn't change anything. |
try running boilerplate.py and commit the results. On the plus side, this means that test is working! On the down side it is a bit annoying.... |
I suspect what happened is that between when the tests on#11204 ran and it got merged something that changed pyplot got merged into master. |
2bdffec
to1ab9b49
CompareThere 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 think the 'clip' kwarg can be removed.
lib/matplotlib/figure.py Outdated
The artist to add to the figure. If the added artist has no | ||
transform set to it previously, its transform will be set to | ||
``figure.transFigure``. | ||
clip : bool, optional, default ``False`` |
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 don't understand this parameter for a Figure artist; I would not expect that anything could be drawn outside the Figure patch boundaries. I did a little test that seemed to confirm that even with the ps backend, so there is white space around the figure, a Figure.figimage is clipped, regardless of whether get_clip_on() returns True or False.
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.
What if you dosavefig(bbox_inches='tight')
? If clipping is on, it'll clip the tight bbox (I think, or maybe it will when some of my PRs on this get merged). If clipping is off the figure will get larger...
@@ -0,0 +1,16 @@ | |||
Figure has an `~.figure.Figure.add_artist` method |
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.
"an" -> "a"
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.
The~
cuts it to justadd_artist
, so 'an' is correct here.
@@ -0,0 +1,16 @@ | |||
Figure has an `~.figure.Figure.add_artist` method |
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.
The~
cuts it to justadd_artist
, so 'an' is correct here.
------------------------------------------------- | ||
A method `~.figure.Figure.add_artist` has been added to the | ||
:class:`~.figure.Figure` class, which allows to add artists directly to a |
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.
allows to add artists -> allows artists to be added
lib/matplotlib/figure.py Outdated
---------- | ||
artist : `~matplotlib.artist.Artist` | ||
The artist to add to the figure. If the added artist has no | ||
transform set to it previously, its transform will be set to |
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.
set to it previously -> previously set
artist.set_transform(self.transFigure) | ||
if clip: | ||
artist.set_clip_path(self.patch) |
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.
This should always be passed, unless you can guarantee that the clip path was alwaysFalse
, or it should default toNone
if you really don't want to change the existing setting. That is, assuming it has an effect (re.@efiring's comment).
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.
Actually, I think I misread this, and thoughtclip
was being passed down. Since it isn't, this doesn't really matter.
ImportanceOfBeingErnest commentedMay 16, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The difference between Default (i.e. clip=False)
With If people think this should be handled differently, I'm happy to change it. Unfortunately I'm not quite sure I understood the comments above. |
My potential objections have been shown to be invalid.
1ab9b49
to00e0ac4
CompareThis seems done, and can/should go in for 3.0. Needs a rebase and another approver... |
1158162
to6024bf3
CompareI rebased. There was still a comment by@QuLogic, which I did not fully understand; so maybe he wants to take another look and either approve or clarify that issue? |
e60a0f3
to0ade33e
CompareI needed to rebase yet again; now there is an error from circle/ci saying |
Yeah, unfortunately while the release candidate for 3.0 is cut, the whats-new should be moved to the actual whats-new.rst. |
0ade33e
to5d208e9
CompareNow I get |
lib/matplotlib/tests/test_figure.py Outdated
@@ -381,6 +382,34 @@ def test_warn_cl_plus_tl(): | |||
assert not(fig.get_constrained_layout()) | |||
def test_add_artist(): |
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.
You may want to (but don't have to) use#11408 for the test, which has the benefit of directly taking care of all three output formats and generating failure diffs when needed.
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.
Ok, did that. Locally, the svg test always skips though. Not sure about the reason.
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.
You just don't have inkscape installed. I wouldn't worry about it...
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 have several inkscape versions installed, maybe that's the problem.
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, shouldn't have assumed; rephrase - inkscape wasn't callable for some reason 😉
5d208e9
toe4e5a0b
Comparee4e5a0b
tob6326cc
Compare
Uh oh!
There was an error while loading.Please reload this page.
PR Summary
As quickly discussedon gitter, an
add_artist()
ofFigure
may be useful in some cases.This PR would add such method.
PR Checklist
, with examples if plot related