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

Skip to content

ENH: Add ellipse class for annotation box styles #24596

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 7 commits into from
Dec 8, 2022

Conversation

ckcherry23
Copy link
Contributor

@ckcherry23 ckcherry23 commented Dec 3, 2022

PR Summary

Create a new 'Ellipse' annotation box style that is modelled by the 'Circle' class
Fixes #24568

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/ [N/A]
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@ckcherry23 ckcherry23 changed the title Add ellipse class for annotation box styles ENH: Add ellipse class for annotation box styles Dec 3, 2022
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@oscargus
Copy link
Member

oscargus commented Dec 3, 2022

Looks promising!

If you can add info here:

# Square ``square`` pad=0.3
# ========== ============== ==========================

of the new shape.

Here one can see that it is working:
image

I'll add some comments in the code as well.

There is a failing test at the moment. It should just be to update the test image so that includes the ellipse as well.

@oscargus
Copy link
Member

oscargus commented Dec 3, 2022

This is the current test image:
image

which will now also include the ellipse. So updating that image after rerunning the test, copying from result_images to baseline_images will have the tests pass and the new code tested.

@oscargus
Copy link
Member

oscargus commented Dec 3, 2022

Oh, and I think that it may be worthwhile to highlight this addition through a What's new note. If you want to, write some short text and a minor example showing how it can be used. See examples is https://github.com/matplotlib/matplotlib/tree/main/doc/users/next_whats_new

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.

modulo fixing the docs build.

@tacaswell tacaswell mentioned this pull request Dec 3, 2022
1 task
@ckcherry23 ckcherry23 marked this pull request as ready for review December 4, 2022 08:18
@ckcherry23 ckcherry23 requested a review from oscargus December 4, 2022 09:13
@tacaswell tacaswell added this to the v3.7.0 milestone Dec 4, 2022
@tacaswell
Copy link
Member

Looks good, thank you @ckcherry23 ! We are just waiting for a second review.

@oscargus
Copy link
Member

oscargus commented Dec 4, 2022

Agree that it looks good! Let me just check the equations (now it seems like the padding is scaled, but I cannot really get my head around it as it looks like the padding is scaled down by sqrt(2), but in the image it looks like the padding has increased if anything).

@oscargus
Copy link
Member

oscargus commented Dec 4, 2022

OK, there is a slightly different behavior of the pad here, but I am not sure if it is a problem or not. Nor if it is worthwhile to redo the code.

Here is what happens with circle, this and what possibly may be a preferred interpretation of pad:

image

As seen, for circle, the leftmost, the padding is on the radius of the circle. For this PR, the middle, the padding is on the bounding box and then the ellipse is touching the padded box. One may think that the padding could be as in the rightmost figure, but I do not think that it is a problem as one probably will try to figure out a good padding anyway.

(I also realized that with pad=0 a circle does not always enclose all the text. One can try this with plt.text(0.5, 0.5, "M", bbox={'boxstyle': 'circle,pad=0'}, fontsize=40).)

I'll approve this as the code is good as such, but not merge it to get a second opinion on the behavior.

Thanks for your effort!

Copy link
Member

@oscargus oscargus left a comment

Choose a reason for hiding this comment

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

Good code, but would like to have a second opinion on the behavior.

@tacaswell
Copy link
Member

  • Pro of just merging now: get it in!
  • con of just merging now: may have to regenerate a test image

@jklymak
Copy link
Member

jklymak commented Dec 6, 2022

@oscargus how are you defining the angle on the pad in the above? Is it going through the center of the text bounding box?

@oscargus
Copy link
Member

oscargus commented Dec 6, 2022

That was my idea, yes, as that seems to be a quite natural way to define it, closest distance to the bounding box (although any angle will have that...). But I guess that there are more options, like 45 degrees.

Considering that the Circle pad is a bit different compared to the others, I am not sure if it actually matters that Ellipse is a bit "off" as well. I guess my main idea was that the pad should be visually similar for the same value.

@oscargus
Copy link
Member

oscargus commented Dec 6, 2022

Another reason is that the equations become a bit easier for that case, compared to e.g. 45 degrees, although the computational burden is not that huge anyway.

Edit: actually, they are straightforward for 45 degrees as well.

@tacaswell
Copy link
Member

On a bit more consideration I think that there are a bunch of reasonable definitions of pad and there is really only one degree of freedom here. It is not clear to me one definition of pad is more obviously right or more natural nor is it clear that the definition of pad should be consistent between different annotations styles (I expect these to be tuned by what "looks good' and I really hope that people do not try to encode quantitative information into the size of the annotation boxes over what is needed to fit the text....). In addition to the two proposal I could also see pad being what is needed for either the major or minor axis to be tangent to the sides of text size (which seems to be the generalization of Circle's pad?).

I'm in favor of merging this as-is and accept the apparent inconsistency because the inconsistency is inevitable.

@oscargus oscargus merged commit d7e050b into matplotlib:main Dec 8, 2022
@oscargus
Copy link
Member

oscargus commented Dec 8, 2022

Thanks @ckcherry23 ! Hope to see you around!

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.

[ENH]: Ellipse annotation
4 participants