推荐学习书目
› 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 · Oct 24, 2018 · 9314 views
    This topic created in 2899 days ago, the information mentioned may be changed or developed.
    plt.legend()提示 No handles with labels found to put in legend,不能正常显示 legend,不知哪里出问题,使用环境为 Spyder。
    2 replies  •  2018-10-24 10:30:39 +08:00
    xider
        1
    xider  
       Oct 24, 2018 via Android
    没有代码看不出问题
    songdg
        2
    songdg  
    OP
       Oct 24, 2018
    这是书上的一个例子,我发现不用 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()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   800 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:56 · PVG 03:56 · LAX 12:56 · JFK 15:56
    ♥ Do have faith in what you're doing.