Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
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.