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]: Make "No artists with labels found to put in legend" a warning #27145

Closed
Milestone
@Jacob-Stevens-Haas

Description

@Jacob-Stevens-Haas

Problem

When I receive this issue, it's hard to debug and find the specific call toax.legend() if I can't raise Warnings to Exceptions. I sometimes nest plotting functions in order to draw the same plot different ways or arrange plots in a composite figure, depending upon the presentation.

MWE and Full message:

frommatplotlibimportpyplotaspltimportwarningswarnings.simplefilter("error",category=Warning)plt.plot([1,2,3])plt.legend()

(no error, plot appears)

No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.

Proposed solution

Make this a trueUserWarning. Currently, it's alogging.LogRecord of level=logging.Warning.

log=logging.getLogger(__name__)...log.warning(<thismessage>)

Additional pro: In the future, it would be easier to find and work on this warning if it is, in fact, a trueWarning.

Con: It won't be handled by the logging infrastructure. But legend.py uses the default module logger, and the onlyLogRecord that it emits is this one. The only situation I could think of where this might matter is if a user has some override of global logging setup (by callinglogging.setLoggerClass()) but does not apply a similar philosophy to capturing warnings in STDERR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp