AllenDowney/ThinkDSP

"No handles with labels found to put in legend" issue

esunlon opened this issue · 8 comments

Hi all
i just read the chapter 1 and ready to code a little bit. after cloned the repo, i run a few codes and python give me this words:No handles with labels found to put in legend. i googled something, but no results.
here is my codes, my running env is anaconda 3.5.2
issue
:

from __future__ import print_function, division

# %matplotlib inline
import thinkdsp
import thinkplot

import numpy as np

cos_sig = thinkdsp.CosSignal(freq=440, amp=10, offset=0)
sin_sig = thinkdsp.SinSignal(freq=880, amp=0.5, offset=0)

cos_sig.plot()
thinkplot.config(xlabel='Time (s)', ylabel='amp(p)')

I have the same issue

Same. A good reason to learn the underlying matplotlib interface, and not just the thinkplot wrapper.

nickk commented

Shouldn't the config line be before the plot line? i.e.:
thinkplot.config(xlabel='Time (s)', ylabel='amp(p)')
cos_sig.plot()

If I run your code I don't get an error but my graph has no legend labels. Switching the lines around fixes that.

Think should be resolved now with a newer version of thinkplot.py

But let me know if it is not.

The issue isn't resolved yet.
Screenshot at 2020-03-26 18-10-08

I am using spyder 4.0.1 and having the same issue. Not getting axes, legends, labels or titles even though I am declaring it in the code. Thanks.

Sounds like there are two issues:

  1. Still getting a warning if there are no labels. Ok, I am working on changes now that will get rid of thinkplot.py altogether, and this problem should go with it.

  2. Figures don't show up right in spyder. I'm not sure what the problem is, but I don't recommend using spyder for Jupyter notebooks.

I face this same issue with "matplotlib". It turned out that my plot axis was getting cleared before I was putting the legends. If "thinkplot" is based on "matplotlib" it might help the developer in debugging