Matplotlib Legends not working

后端 未结 4 1314
无人及你
无人及你 2020-12-07 10:51

Ever since upgrading matplotlib I get the following error whenever trying to create a legend:

/usr/lib/pymodules/python2.7/matplotlib/legend.py:610: UserWarn         


        
4条回答
  •  一生所求
    2020-12-07 11:14

    Use handles AKA Proxy artists

    import matplotlib.lines as mlines
    import matplotlib.pyplot as plt
    # defining legend style and data
    blue_line = mlines.Line2D([], [], color='blue', label='My Label')
    reds_line = mlines.Line2D([], [], color='red', label='My Othes')
    
    plt.legend(handles=[blue_line, reds_line])
    
    plt.show()
    

提交回复
热议问题