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

ENH: Change logging to warning when creating a legend with no labels#27172

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

Merged
timhoffm merged 7 commits intomatplotlib:mainfromJacob-Stevens-Haas:27145-convert-legend-warning
Dec 1, 2023
Merged

ENH: Change logging to warning when creating a legend with no labels#27172

timhoffm merged 7 commits intomatplotlib:mainfromJacob-Stevens-Haas:27145-convert-legend-warning
Dec 1, 2023

Conversation

Jacob-Stevens-Haas
Copy link
Contributor

@Jacob-Stevens-HaasJacob-Stevens-Haas commentedOct 23, 2023
edited
Loading

Fixes#27145

Also add test_legend_nolabels_warning()

PR summary

After discussion in the linked issue, it was determined thatwarnings.warn() was better thanlog.warning() for alerting users that we can't draw a legend if there are no labels. This PR implements the change fromlog.warning() towarnings.warn (actually,_api.warn_external())

PR checklist

@Jacob-Stevens-Haas

This comment was marked as outdated.

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.

@Jacob-Stevens-Haas

This comment was marked as duplicate.

@Jacob-Stevens-HaasJacob-Stevens-Haas marked this pull request as ready for reviewOctober 24, 2023 12:32
@Jacob-Stevens-HaasJacob-Stevens-Haas marked this pull request as draftOctober 24, 2023 12:34
@Jacob-Stevens-Haas
Copy link
ContributorAuthor

Jacob-Stevens-Haas commentedOct 24, 2023
edited
Loading

Ok, I think I'm at a place I need help from a reviewer.

  • Only CI failure is in coverage of test suite, and only where there's some condition dealing with localization. [How] should I deal with this?
  • Does "New Features andAPI Changes are noted with adirective and release note" apply to this change?
  • Is the wording inAxes docstring and wording/change in galleries/examples/text_labels_and_annotations/custom_legends.py sensible?

@Jacob-Stevens-HaasJacob-Stevens-Haas marked this pull request as ready for reviewOctober 24, 2023 14:26
Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

You can ignore coverage. It's sometimes doing funny things because of our CI setup.

Jacob-Stevens-Haas reacted with thumbs up emoji
Also:DOC: Correct Axes docstring when no labels in legend.
@Jacob-Stevens-Haas
Copy link
ContributorAuthor

Hey is there anything that I need to do to merge this?

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

Sorry this slipped through. Thanks for the reminder.

@@ -1072,7 +1073,7 @@ def test_legend_labelcolor_rcparam_markerfacecolor_short():


def test_get_set_draggable():
legend = plt.legend()
legend = plt.legend(labels=["mock data"])
Copy link
Member

@timhoffmtimhoffmNov 13, 2023
edited
Loading

Choose a reason for hiding this comment

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

I'm somewhat uneasy about this pattern of providing labels when there is no data.

  1. Passing labels only is supported but discouraged.
  2. While currently supported, it feels, that passing more labels than we have data should possibly warn as well. At least it's non-sensical. - But that'd be a separate PR. For here, we should just not use this pattern.

I suggest to silence the warning explicitly rather than through a sketchy code construct: Decorate the function with

@pytest.mark.filterwarnings("ignore:No artists with labels found to put in legend")

instead.

Also in the following test functions.

Jacob-Stevens-Haas reacted with thumbs up emoji
plt.plot([1, 2, 3])
with warnings.catch_warnings():
warnings.simplefilter("ignore")
plt.legend()
Copy link
Member

Choose a reason for hiding this comment

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

Let's at least make sure, a legend is created and attached to the Axes:

Suggested change
plt.legend()
plt.legend()
assertplt.gca().get_legend()isnotNone

Jacob-Stevens-Haas reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Gotcha, makes sense! In addition, is pattern you suggested above of@pytest.mark.filterwarnings(...) preferable towarnings.catch_warnings()+simplefilter pattern?

Also assert that a legend is at least created
@timhoffmtimhoffm merged commitee241ad intomatplotlib:mainDec 1, 2023
@timhoffm
Copy link
Member

Thanks, and congratulations on your first contribution to Matplotlib! We hope to see you back. 😄

Jacob-Stevens-Haas reacted with laugh emoji

@QuLogicQuLogic added this to thev3.9.0 milestoneDec 1, 2023
@Jacob-Stevens-HaasJacob-Stevens-Haas deleted the 27145-convert-legend-warning branchDecember 6, 2023 11:42
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jklymakjklymakjklymak left review comments

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

@timhoffmtimhoffmtimhoffm approved these changes

@scottshambaughscottshambaughscottshambaugh approved these changes

Assignees
No one assigned
Labels
None yet
Projects
Milestone
v3.9.0
Development

Successfully merging this pull request may close these issues.

[ENH]: Make "No artists with labels found to put in legend" a warning
5 participants
@Jacob-Stevens-Haas@timhoffm@jklymak@scottshambaugh@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp