Skip to content
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

Fixed legend with legend location "best" when legend overlaps shaded area and text #27469

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

alanlau28
Copy link
Contributor

PR summary

This PR fixes bug #27414 and #23323. The calculation of badness in the legend location for 'best' now considers PolyCollection and Text. For PolyCollection, the paths are now converted to lines to check for hit detection when placing a legend. For Text, the bounding box is now checked for overlap.

PR checklist

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 week or so, please leave a new comment below and that should bring it to our attention. 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.

Comment on lines 986 to 989
if isinstance(artist, PolyCollection):
paths = artist.get_paths()
for path in paths:
lines.append(artist.get_transform().transform_path(path))
Copy link
Member

Choose a reason for hiding this comment

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

I would probably just have this in the if/elif chain rather than inside of one of the cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ksunden
Copy link
Member

ksunden commented Dec 8, 2023

I do believe this should have a behavior change note, while "best" is intentionally 'we take care of it for you' and so I don't necessarily think it can't change, noting when the change occurs is something we should do.

@alextanned
Copy link
Contributor

I do believe this should have a behavior change note, while "best" is intentionally 'we take care of it for you' and so I don't necessarily think it can't change, noting when the change occurs is something we should do.

I agree. How does the newly added note look?

@QuLogic
Copy link
Member

QuLogic commented Dec 9, 2023

Please see the instructions in our contribution guide.

@alextanned
Copy link
Contributor

alextanned commented Dec 9, 2023

Hello, could you please provide some guidance on the failed tests? How should I address the PR cleanliness?

@rcomer
Copy link
Member

rcomer commented Dec 9, 2023

The PR cleanliness failure is because you replaced a test image twice. We don't want any more images in the commit history than necessary, so you will need to squash the commits down.

To squash, you can do an interactive rebase. I strongly recommend saving a backup copy of your branch first if you have not done this (much) before.

@alanlau28 alanlau28 force-pushed the fix-legend-loc branch 2 times, most recently from 685e6f1 to 474bf00 Compare December 9, 2023 20:44
lib/matplotlib/legend.py Outdated Show resolved Hide resolved
Copy link
Contributor

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

Looks good to me!

@alanlau28 if you can reduce the number of commits that would be great (rebase and fixup/squash)! If not, we just have to remember to squash while merging.

@QuLogic
Copy link
Member

QuLogic commented Dec 15, 2023

Yes, we definitely do not want these "Empty-Commit" commits with nothing in them.

@dstansby
Copy link
Member

This looks good to go - it just needs rebasing on to the current main branch. @alanlau28 would you be able to do that? Let us know if you want any help, or someone else to do it.

Co-authored-by: alextanned <74106760+alextanned@users.noreply.github.com>
@rcomer
Copy link
Member

rcomer commented Jan 21, 2024

I think it would be good to get this in, so I took the liberty of rebasing and squashing. The conflict was just because an adjacent branch of the if-loop was modified at #27517.

@ksunden ksunden added this to the v3.9.0 milestone Jan 23, 2024
@ksunden ksunden merged commit f976947 into matplotlib:main Jan 23, 2024
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: API files in lib/ and doc/api topic: legend
Projects
8 participants