2

Sorry if this has been asked before but all the answers I found didn't work for me. I'm looking for a way to suppress this warning. The context is that I wrote a function that creates a lot of plots and sometimes I can't help but creating a legend for an unlabeled curve.

This is my sample code including what I tried

import matplotlib.pyplot as plt

import warnings
warnings.filterwarnings('ignore') # doesn't work

import logging
logging.basicConfig(level=logging.CRITICAL) # doesn't work

plt.plot(np.random.rand(10))
plt.legend()
plt.show()

The warning still appears like this

WARNING:matplotlib.legend:No handles with labels found to put in legend.
rhedak
  • 399
  • 4
  • 13
  • The `logging` option works well for me and I get the figure with no legend and no warning. Python 3.8, matplotlib 3.1.2. Also in python 2.7. – Francisca Concha-Ramírez Nov 25 '19 at 15:38
  • 1
    thanks I dug a bit deeper and found a solution in another stack overflow question logging.getLogger().setLevel(logging.CRITICAL) Maybe it was related to using Jupyter Notebook – rhedak Nov 25 '19 at 23:20

1 Answers1

2

I found a solution in this Stack Overflow Question.

Disable INFO logging messages in Ipython Notebook

Maybe It was related to Jupyter Notebook?

import logging
logging.getLogger().setLevel(logging.CRITICAL)
rhedak
  • 399
  • 4
  • 13