Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add itemboxalign option to legend constructor#29197

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
skkestrel wants to merge2 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromskkestrel:legend-itemboxalign

Conversation

skkestrel
Copy link

PR summary

This pull request adds the option "itemboxalign" to the Legend constructor. From the proposed announcement .rst:

Legend previously always aligns items using the "baseline" option, which results in
the appearance of vertical centering of the artist and label for multi-line labels.
This is sometimes hard to read. The introduction of theitemboxalign parameter to the Legend constructor
allows the user to change this behavior and choose a different desired vertical alignment.

import matplotlib.pyplot as pltfig, ax = plt.subplots(1, 2)ax[0].plot([5, 2, 8], label='long\nlabel')ax[0].plot([4, 9, 1], label='another\nlong\nlabel')ax[0].legend(title="align=baseline (default)")ax[1].plot([5, 2, 8], label='long\nlabel')ax[1].plot([4, 9, 1], label='another\nlong\nlabel')ax[1].legend(title="align=top", itemboxalign='top')plt.show()

image

I chose the name "itemboxalign" on a whim based on the existing rendering code in Legend. I think the name could be better, such as:

itemboxalignment
itemboxverticalalign
itemboxverticalalign(ment)
labelverticalalign(ment)

PR checklist

Copy link

@github-actionsgithub-actionsbot 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 uson gitter for real-time discussion.

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

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

@timhoffm
Copy link
Member

timhoffm commentedNov 28, 2024
edited
Loading

Thanks for the contribution. This looks fundamentally reasonable. I'm still thinking about proper naming.

Note: We unfortunately have analignment parameter that only covers the horizontal alignment of title and content and is thus too generic and semantically overlapping the alignment here. But for backward-compatibility we cannot change that.

The new naming needs to be more specific, butitemboxalign feels very technical and it may be hard to guess what it is doing. Maybehandlealignment? If one wanted to be very precisehandle_vertical_alignment, but that's quite long. Suggestions welcome.

@skkestrel
Copy link
Author

I'll also note that in Legend documentation, the term "entry" is also used for the marker+label combination:

alignment{'center', 'left', 'right'}, default: 'center'
The alignment of the legend title and the box ofentries. The entries are aligned as a single block, so that markers always lined up.

So, perhaps alsoentryalignment orentry_vertical_alignment - but I would argue that there's not much sense in talking about horizontal alignment of individual entries, so I slightly prefer the shorterentryalignment orhandlealignment.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
Status: Needs review
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@skkestrel@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp