FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add fig.add_artist method by ImportanceOfBeingErnest · Pull Request #11234 · matplotlib/matplotlib · GitHub

Repository navigation

Add fig.add_artist method - #11234

Merged
tacaswell merged 1 commit into
matplotlib:masterfrom
ImportanceOfBeingErnest:fig-add-artist
Jul 19, 2018
Merged

tacaswell merged 1 commit into
matplotlib:masterfrom
ImportanceOfBeingErnest:fig-add-artist

Conversation

ImportanceOfBeingErnest commented May 11, 2018 •
edited
Loading

Copy link
Copy Markdown
Member

PR Summary

As quickly discussed on gitter, an add_artist() of Figure may be useful in some cases.
This PR would add such method.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)

jklymak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks great asside frm the small formatting issues! Thanks!

Comment thread 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``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

figure.transFigure?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think ideally this docstring would be numpydoc compliant. Most of figure.py is not, but can't hurt to make this new one compliant.

Comment thread 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

ImportanceOfBeingErnest force-pushed the fig-add-artist branch 2 times, most recently from 9969fc4 to f1046f6 Compare May 12, 2018 00:02
dstansby added this to the v3.0 milestone May 12, 2018

In 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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``).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Broken sentence

Comment thread 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Shorter: „Determines whether ...“

Copy link
Copy Markdown
Member Author

It doesn't seem like the failing test is due to anything commited here.

jklymak commented May 14, 2018

Copy link
Copy Markdown
Member

You might need to rebase....? Looks like #11204 monkeyed w/ boilerplate... ping @anntzer

Copy link
Copy Markdown
Member Author

Rebasing didn't change anything.

Copy link
Copy Markdown
Member

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....

Copy link
Copy Markdown
Member

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.

efiring left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think the 'clip' kwarg can be removed.

Comment thread lib/matplotlib/figure.py
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``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What if you do savefig(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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

"an" -> "a"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The ~ cuts it to just add_artist, so 'an' is correct here.

@@ -0,0 +1,16 @@
Figure has an `~.figure.Figure.add_artist` method

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The ~ cuts it to just add_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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

allows to add artists -> allows artists to be added

Comment thread 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

set to it previously -> previously set

Comment thread lib/matplotlib/figure.py
artist.set_transform(self.transFigure)

if clip:
artist.set_clip_path(self.patch)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This should always be passed, unless you can guarantee that the clip path was always False, or it should default to None if you really don't want to change the existing setting. That is, assuming it has an effect (re. @efiring's comment).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Actually, I think I misread this, and thought clip was being passed down. Since it isn't, this doesn't really matter.

ImportanceOfBeingErnest commented May 16, 2018 •
edited
Loading

Copy link
Copy Markdown
Member Author

The difference between clip=False and clip=True can be observed when saving the figure with the bbox_inches="tight" option.

Default (i.e. clip=False)

import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (3,2)
plt.rcParams["figure.dpi"] = 72

fig, ax = plt.subplots()
c = plt.Circle((0,0),0.2)
fig.add_artist(c)
fig.savefig("test1.png", facecolor="azure", bbox_inches="tight")

With clip=True:

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. @efiring and @QuLogic, could you explain a bit more in detail what you have in mind concerning the clip option?

efiring dismissed their stale review May 16, 2018 19:00

My potential objections have been shown to be invalid.

jklymak added status: needs rebase Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labels Jul 5, 2018

jklymak commented Jul 5, 2018

Copy link
Copy Markdown
Member

This seems done, and can/should go in for 3.0. Needs a rebase and another approver...

ImportanceOfBeingErnest force-pushed the fig-add-artist branch 2 times, most recently from 1158162 to 6024bf3 Compare July 5, 2018 19:08

Copy link
Copy Markdown
Member Author

I 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?

jklymak requested a review from QuLogic July 13, 2018 22:54
ImportanceOfBeingErnest force-pushed the fig-add-artist branch 2 times, most recently from e60a0f3 to 0ade33e Compare July 13, 2018 23:23

Copy link
Copy Markdown
Member Author

I needed to rebase yet again; now there is an error from circle/ci saying document not included in any doctree.

jklymak commented Jul 14, 2018

Copy link
Copy Markdown
Member

Yeah, unfortunately while the release candidate for 3.0 is cut, the whats-new should be moved to the actual whats-new.rst.

Copy link
Copy Markdown
Member Author

Now I get Analysis Failed (could not build the merge commit), but I looking at the log, I don't see what's failing (which is probably due to me not knowing what to look for in this long log file).

Comment thread lib/matplotlib/tests/test_figure.py Outdated
assert not(fig.get_constrained_layout())


def test_add_artist():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ok, did that. Locally, the svg test always skips though. Not sure about the reason.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You just don't have inkscape installed. I wouldn't worry about it...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I have several inkscape versions installed, maybe that's the problem.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

...sorry, shouldn't have assumed; rephrase - inkscape wasn't callable for some reason 😉

tacaswell merged commit ac58f1f into matplotlib:master Jul 19, 2018
ImportanceOfBeingErnest deleted the fig-add-artist branch February 17, 2019 23:08
This file contains hidden or 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL