Python pylab绘图图例错误

Python pylab绘图图例错误,python,plot,matplotlib,Python,Plot,Matplotlib,我正在尝试设置图例以在图形中绘制数据 但我的代码中似乎有一个错误。 在为绘图设置图例的行中出现以下错误: a.set_transform(self.get_transform()) AttributeError: 'NoneType' object has no attribute 'set_transform' 我的代码如下: import numpy as np; from pylab import *; newData = np.array([[1,2],[2,3],[3,4]]) A

我正在尝试设置图例以在图形中绘制数据

但我的代码中似乎有一个错误。 在为绘图设置图例的行中出现以下错误:

a.set_transform(self.get_transform())
AttributeError: 'NoneType' object has no attribute 'set_transform'
我的代码如下:

import numpy as np;
from pylab import *;

newData = np.array([[1,2],[2,3],[3,4]])
Action = 'abc'

line1 = 'class 0-' + Action
line2 = 'class 1 -others'

plot(newData[:,0],newData[:,1],'-')
figlegend( (line1, line2),('*', '-'),'upper right' )

hold(True)
plot(newData[:,1],newData[:,0],'*')
grid(True)
show()

如果尚未在代码中指定,请使用
set\u transform
方法将其设置为对象,代码将按预期工作

比如说

a = figlegend( (line1, line2),('*', '-'),'upper right' )
a.set_transform(self.get_transform())
有关图例用法的另一个示例,请参见