Skip to content

Move Text init to end of Annotation init. #15747

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

Merged
merged 2 commits into from
Mar 24, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Nov 22, 2019

PR Summary

... in case some kwargs (each of which is handled by calling a set_foo)
need to refer to arrow_patch). Closes #15745.

I nearly told the OP of #15745 that he needed to create an annotation without setting axes and figure because add_text (like add_line) would take care of it for him... but _add_text is private, for some reason (probably should be public, like add_line and friends?)

Small neighboring cleanup in a separate commit.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 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)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@timhoffm
Copy link
Member

timhoffm commented Nov 22, 2019

Not sure if this is a good design pattern overall. We require Text to pass through arbitrary kwargs. Text() in turn splits __init__ into

def __init__(self, ..., kwargs):
    Artist.__init__(self)
    # set up attributes
    self.update(kwargs)

Would that pattern be suitable for Annotation itself as well?

@anntzer
Copy link
Contributor Author

anntzer commented Nov 23, 2019

That looks better to me, adapted accordingly.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

I suppose this is ok.

A bit hesitant because this changes the code path for Text properties. They are not initialized via Text.__init__ anymore but via a deffered update(). In a way, this assumes something about the inner workings of Text. OTOH, t = Text(); t.update(kwargs) is public and the effect is (and I assume is guaranteed) to be equivalent to Text(**kwargs). The former might just be (I think currently is not) a little more inefficient.

IMHO the really clean approach would be to pass Text properties to Text.__init__() and update properties specific to Annotation. But maybe we don't hae to overdo it here.

... in case some kwargs (each of which is handled by calling a set_foo)
need to refer to arrow_patch.
@anntzer
Copy link
Contributor Author

anntzer commented Feb 13, 2020

Actually, instead of splitting Text init in two, I can move the whole init after setting up the arrow_patch, which should alleviate your concerns.

@QuLogic QuLogic added this to the v3.3.0 milestone Mar 24, 2020
@QuLogic QuLogic merged commit 2ff579d into matplotlib:master Mar 24, 2020
@anntzer anntzer deleted the annotationinit branch March 24, 2020 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to add annotate to figure
3 participants