legend()缺少1个必需的位置参数:'标签',Matplotlib

时间:2014-12-08 16:40:12

标签: python matplotlib

我的程序有问题。我尝试使用带有部门颜色的字典来绘制图例,但是当我运行程序时,总是遇到同样的错误:

legend() missing 1 required positional argument: 'labels'.

理论上我总是在我的句柄中有这个变量(就像在这个例子中http://matplotlib.org/users/legend_guide.html#proxy-legend-handles)。这是我的代码:

import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8.27, 11.69), dpi=100)
dep_color = {'a':'red','b':'blue','c':'green'}
label = []
for dep in dep_color:
    P.append(mpatches.Patch(color=dep_color[dep], label=dep))
    label.append(dep)
label = tuple(label)
plt.legend(handles=P,labels = label,bbox_to_anchor=(0.,1.02,1.,.102), loc=3,ncol=3, mode="expand", borderaxespad=0.)

编辑:已更正

0 个答案:

没有答案