2012-07-10 69 views
2

是否有可能将一个大传奇分成多个(通常是2个)较小的传奇。在matploblib中拆分图例

from pylab import * 

t = arange(0.0, 2.0, 0.01) 
s = sin(2*pi*t) 
plot(t, s, linewidth=1.0, label="Graph1") 
grid(True) 
s = sin(4*pi*t) 
plot(t, s, color='r',linewidth=1.0, label="Graph2") 

legend(loc='lower left') 
show() 

我想将图例拆分为两部分,并将它们放在可用空白处。

回答

2

我得到的答案从http://matplotlib.sourceforge.net/users/plotting/examples/simple_legend02.py

from pylab import * 

t = arange(0.0, 2.0, 0.01) 
s = sin(2*pi*t) 
p1, = plot(t, s, linewidth=1.0, label="Graph1") 
grid(True) 
s = sin(4*pi*t) 
p2, = plot(t, s, color='r',linewidth=1.0, label="Graph2") 

l1 = legend([p1], ["Graph1"], loc=1) 
l2 = legend([p2], ["Graph2"], loc=4) 
gca().add_artist(l1) 

show() 

在这里,唯一的缺点是我必须给标签的两倍。

enter image description here