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.