2012-03-17 51 views
0

我想设置图例中的绘图数据。pylab绘图图例错误

但我的代码似乎有错误。 我有以下的错误,在这里我设置一个传奇的情节线:

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() 

回答

0

你有没有在你的代码分配,将其设置为使用set_transform方法的对象,并且代码将按预期工作。

例如

a = figlegend((line1, line2),('*', '-'),'upper right') 
a.set_transform(self.get_transform()) 

用于说明使用方法的另一示例,请参见Matplotlib Legend Demo