Skip to content

Clip annotations if annotation_clip is not False and clip_on is not set #15096

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

Closed
wants to merge 1 commit into from

Conversation

2xB
Copy link

@2xB 2xB commented Aug 21, 2019

PR Summary

If an annotation is created using e.g. plt.annotate(xy=(3, 3), s='test'), then this annotation is clipped on the scene as a default, but still virtually occupies space that leads to a larger bounding box. This goes also for annotation_clip=True. Currently, the parameter clip_on defaults to None, which leads to this exact situation. With this PR, it defaults to True, if annotation_clip is not False. This fixes the original issue while preserving both the ability to change clip_on if wished and leaving the API unchanged, so the result of annotation_clip=False is unchanged.

Fixes #14354.

PR Checklist

Disclamer: This PR is created as bug fix. Therefore, most of the following checklist does not apply. If a unit test for this is desired, I can create one. I am just not sure how a good test would be applied here.

  • 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

Copy link
Member

@ImportanceOfBeingErnest ImportanceOfBeingErnest left a comment

Choose a reason for hiding this comment

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

This is no proper fix. Currently we have the defaults such that annotations are shown outside the axes, as desired:

image

With this PR they would be cut out:

image

I stated the two possible solutions to the problem in #14354 (comment)

@jklymak
Copy link
Member

jklymak commented Aug 21, 2019

Is there any use to annotation_clip and clip_on to ever be different? This seems like a case of annotation having its own API for something the parent Artist class already had.

@ImportanceOfBeingErnest
Copy link
Member

I answered that in #14354 (comment) (to keep discussion in one place).

@2xB
Copy link
Author

2xB commented Aug 21, 2019

@ImportanceOfBeingErnest Could you please provide the code you used for the image comparison? I think I am just not aware of the way you use annotations. In the way I would create this figure the PR does not have that influence.

@2xB
Copy link
Author

2xB commented Aug 21, 2019

And btw. thank you very much for investing the time to explain, this is really helpful for me!

@2xB
Copy link
Author

2xB commented Aug 21, 2019

Ooh, looking at your last comment on #14354 and looking at how the failing examples are built, I think I finally got the issue. Thank you very much for spending that time. As a default, annotations can currently leave the plot range and still be painted as long as their origin is on the visible part of the plot. I always thought that since in my example, obviously the annotations are not visible, they would be painted on the plot which is in its entirety invisible at that point. But instead, they are just not plotted, because their origin is not in the visible area. Now I also understand why you mean it would be hacky to solve this.

Thank you very much again!

@2xB 2xB closed this Aug 21, 2019
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.

Annotations are not clipped properly
3 participants