V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
songdg
V2EX  ›  Python

Matplotlib: No handles with labels found to put in legend.

  •  
  •   songdg · 2018-10-24 10:03:10 +08:00 · 8287 次点击
    这是一个创建于 1982 天前的主题,其中的信息可能已经有所发展或是发生改变。
    plt.legend()提示 No handles with labels found to put in legend,不能正常显示 legend,不知哪里出问题,使用环境为 Spyder。
    2 条回复    2018-10-24 10:30:39 +08:00
    xider
        1
    xider  
       2018-10-24 10:12:46 +08:00 via Android
    没有代码看不出问题
    songdg
        2
    songdg  
    OP
       2018-10-24 10:30:39 +08:00
    这是书上的一个例子,我发现不用 plt.show()就能显示,但是 plt.legend(loc=(0.64,0.1))就显示上面的提示。
    import matplotlib.pyplot as plt

    d = [11,12,13,14,15,16,17]

    t0 = [15.3,12.6,12.7,13.2,12.3,11.4,12.8]
    t1 = [26.1,26.2,24.3,25.1,26.7,27.8,26.9]
    t2 = [22.3,20.6,19.8,21.6,21.3,19.4,21.4]

    plt.plot(d,t0,label='Tokyo')
    plt.plot(d,t1,label='Hawaii')
    plt.plot(d,t2,label='Hong Kong')

    plt.xlim(11,15)
    plt.ylim(0,30)

    plt.xlabel('Date',size=12,fontweight='semibold')
    plt.ylabel('Temperature (°C)',size=12,fontweight='semibold')

    plt.grid(True,linewidth=0.5,color='#aaaaaa',linestyle='-')

    plt.title("Daily temperature of 3 cities in the second week of December", size=14, fontweight='bold')

    plt.legend(loc=(0.64,0.1))
    plt.show()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   957 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:43 · PVG 05:43 · LAX 14:43 · JFK 17:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.