matplotlib中图例句柄的基本示例中的typeerror

Jan*_*Jan 4 python matplotlib

我很难理解传奇处理.更多,来自官方matplotlib图例指南的基本示例

import matplotlib.pyplot as plt
line_up, = plt.plot([1,2,3], label='Line 2')
line_down, = plt.plot([3,2,1], label='Line 1')
plt.legend(handles=[line_up, line_down])
Run Code Online (Sandbox Code Playgroud)

失败了TypeError: __init__() got multiple values for keyword argument 'handles'.

我究竟做错了什么?有任何想法吗?

我的matplotlib版本是1.3.1.我在Ubuntu 14.04 ..

这是完整的回溯(在python脚本中有上面的行)

heiland@note121:bauHS15_iomapsgenpod$ python testleg.py 
Traceback (most recent call last):
  File "testleg.py", line 4, in <module>
    plt.legend(handles=[line_up, line_down])
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 3381, in legend
    ret = gca().legend(*args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 4778, in legend
    self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
TypeError: __init__() got multiple values for keyword argument 'handles'
Run Code Online (Sandbox Code Playgroud)

Kob*_*i K 9

只需删除handles关键字

像这样使用它:

import matplotlib.pyplot as plt
line_up, = plt.plot([1,2,3], label='Line 2')
line_down, = plt.plot([3,2,1], label='Line 1')
plt.legend([line_up, line_down])
Run Code Online (Sandbox Code Playgroud)