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

Fix legendlabelcolor=‘linecolor’ to handle various corner cases, e.g. step histograms and transparent markers#30328

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
lukashergt wants to merge6 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromlukashergt:fix-legend-labelcolor-linecolor

Conversation

lukashergt
Copy link

@lukashergtlukashergt commentedJul 18, 2025
edited
Loading

PR summary

This PR addresses issue#30298, which pointed out some corner cases, wherelabelcolor='linecolor' did not work as expected, e.g.:

  • histograms withhisttype='step' or scatter plots withfc='none' had an empty legend label.
  • plots that specifiedmec andmfc but notc would end up with non-matching handle and label colours.

The failing checks inthis test from commitdabaf62 highlight the issue.

Changes:

  • Change'linecolor' ordering of checks fromc, fc tomfc, fc, mec, ec, c.
  • Skip whencolor is empty, equal tonone or with a zero alpha value, e.g. whenfc is'none' continue the loop to check whether there is some color inec.

Thanks to@nrnavaneet, who worked on this in#30299, and which this PR is based on.

Closes#30298

PR checklist

nrnavaneet reacted with heart emoji
…o `linecolor`, e.g. ensuring that histograms with `step` histtype do not end up with an empty label
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.

…m `c, fc` to `mfc, fc, mec, ec, c`; check if `color` is empty, `none` or transparent and loop on if so
@nrnavaneet
Copy link
Contributor

nrnavaneet commentedJul 18, 2025
edited
Loading

Nice work@lukashergt ! The tests are really helpful and good. Glad it was fixed by u :) U deserve the credit.

pass
continue
else:
text.set_color('none')
Copy link
Member

Choose a reason for hiding this comment

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

If I understand correctly this is executed as a fallback if color could not be detected. Then, it feels wrong to set full transparency, because it makes the text invisible. I think we should rather leave the default as we did before.

Copy link
Author

@lukashergtlukashergtJul 18, 2025
edited
Loading

Choose a reason for hiding this comment

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

Yes, this is a fallback for the case thatfc,ec, andc all havecontinue-ed through, i.e. they are either of the following:

  • an empty array,
  • 'none' or'None',
  • colour with zero alpha value,
  • AttributeError raised on the getter function.

Otherwise they would have broken (note thebreak statement) out of the loop beforehand, in which case theelse case of thefor ... else ... construction won't get invoked.

Final example case from thetest_legend_labelcolor_linecolor_plot test:

importnumpyasnpimportmatplotlib.pyplotaspltx=np.arange(5)fig,ax=plt.subplots()p=ax.plot(x,'o',c='none',mec='none',label="invisible circles with invisible label")leg=ax.legend(labelcolor='linecolor')
image

So yes, the label entry is invisible because the markers and the legend handle are also invisible. In this stand-alone example this seems nonsensical, but something of this sort might come in handy when trying to insert a dummy legend entry in-between other legend entries for spacing.

Using helper for `'none'` string equality and using the fact that `to_rgba` always returns a 4-element tuple to simplify the code.Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm left review comments

@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
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[Bug]: Legend kwarglabelcolor='linecolor' not working properly whenfacecolor is'None'
3 participants
@lukashergt@nrnavaneet@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp