2012-03-17 54 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