Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Tweak AnnotationBbox coords specification. #26069

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 1 commit into from
Jun 5, 2023

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 4, 2023

In AnnotationBbox, it makes sense to allow passing xycoords and boxcoords positionally, because (similarly to annotate()) something like AnnotationBbox(box, xy1, xy2, "axes transform", "offset points") (for example) actually reads better than
AnnotationBbox(box, xy1, xy2, xycoords="axes transform", boxcoords="offset points") once you've seen this often enough and learn that the positional order is just (annotated_xy, box_xy, annotated_coords, box_coords). (The alternative that's fully explicit would be
AnnotationBbox(box, xy=xy1, xybox=xy2, xycoords=..., boxcoords=...) but even that doesn't read too well because the xy kwargs names don't rhyme exactly with the coords names; or one could reorder the args to AnnotationBbox(box, xy=xy1, xycoords=..., xybox=xy2, boxcoords=...), but that's really a mouthful and doesn't help API usability.)

So let's just allow passing the coordinate systems positionally (undoing the change in Matplotlib 3.6 that made them kwonly). The following kwargs do remain kwonly, though.

In demo_text_path: xycoords defaults to "data" so doesn't need to be specified; xybox is not specified so boxcoords is not needed.

PR summary

PR checklist

In AnnotationBbox, it makes sense to allow passing xycoords and
boxcoords positionally, because (similarly to annotate()) something like
`AnnotationBbox(box, xy1, xy2, "axes transform", "offset points")` (for
example) actually reads better than
`AnnotationBbox(box, xy1, xy2, xycoords="axes transform", boxcoords="offset points")`
once you've seen this often enough and learn that the positional order
is just (annotated_xy, box_xy, annotated_coords, box_coords).  (The
alternative that's fully explicit would be
`AnnotationBbox(box, xy=xy1, xybox=xy2, xycoords=..., boxcoords=...)`
but even that doesn't read too well because the xy kwargs names don't
rhyme exactly with the coords names; or one could reorder the args to
`AnnotationBbox(box, xy=xy1, xycoords=..., xybox=xy2, boxcoords=...)`,
but that's really a mouthful and doesn't help API usability.)

So let's just allow passing the coordinate systems positionally
(undoing the change in Matplotlib 3.6 that made them kwonly).  The
following kwargs do remain kwonly, though.

In demo_text_path: xycoords defaults to "data" so doesn't need to be
specified; xybox is not specified so boxcoords is not needed.
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.

Sounds reasonable.

The better API would be grouping positions and coords together: AnnotationBbox(box, xy1, "axes transform", xybox, "offset points"). But that ship has sailed. While we might have considered this for the rather seldom used AnnotationBbox, we cannot make that change to annotate(), and having different orders between different times of annotations is a non-starter. So this is the best we can go to.

Speaking of which, should we equally limit the use of positional arguments in annotate()?

@anntzer
Copy link
Contributor Author

anntzer commented Jun 5, 2023

Speaking of which, should we equally limit the use of positional arguments in annotate()?

Currently the signature is

    def annotate(self, text, xy, xytext=None, xycoords='data', textcoords=None,
                 arrowprops=None, annotation_clip=None, **kwargs):

I guess you could make annotation_clip kwonly; I'm not really sure it should really be done for arrowprops, because in practice it will often be self-explanatory in the code if you really end up passing all these positionally (e.g. annotate("string", xy, "data", xy1, "offset fontsize", {"arrowstyle": "->"}): writing arrowprops={"arrowstyle": "->"} seems repetitive, and note that arrowprops usually contains an arrowstyle key).

@tacaswell tacaswell added this to the v3.8.0 milestone Jun 5, 2023
@tacaswell
Copy link
Member

Does this need an API change note?

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

I'm 50/50 on this needing an API change note. If anyone feels "no", merge away.

@ksunden
Copy link
Member

ksunden commented Jun 5, 2023

The notes added in the original expiration (#24984) contain the following already, but do not spell out each individual artist's cut off:

Passing all but the very few first arguments positionally in the constructors
of Artists is no longer possible. Most arguments are now keyword-only.

Given that incorrect info is not in the change notes, but the general idea is already (and this is a scaled back version of the deprecation expiring in 3.8 which will have been warning users already) I don't think an additional change not is needed.

@ksunden ksunden merged commit 4e420ca into matplotlib:main Jun 5, 2023
@anntzer anntzer deleted the coordsdata branch June 5, 2023 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants