2013-04-05 61 views
2

我有一堆子图和一个我想包含图例(每个其他子图都有相同数量的手柄和标签,所以我只想要一个全部的主图例)。除了matplotlib subplot中的图例

|plot|gap1|plot| 
|plot|plot|plot| 
|plot|gap2|plot| 

现在在哪里gap1,我想把我的主传奇。我在第一个小区绘制了相同的图。

line1 = ax2.plot(x1,y2,'--',color='b',linewidth=2) 
line2 = ax2.plot(x1,y2,'-',color='r') 
ax2.legend((line1,line2),('line1','line2'),numpoints=1,loc='center') 
l = line1[0] 
l.remove() 
l = line2[0] 
l.remove() 
ax2.set_axis_off() 

但这似乎不起作用。

现在我只想把传说中的中心AX2副区(在GAP1),并删除一切(轴,线,蜱等)除了传说这是在中央。 谢谢。

回答

1
fig, axes_lst = plt.subplots(2, 1) 

ln_1, ln_2 = axes_lst[0].plot(range(5), range(5), range(5), np.arange(5) ** 2) 
axes_lst[1].legend((ln_1, ln_2), ('lin', 'quad'), loc='center') 
plt.draw() 

呼叫传说中所使用的句柄不必须要对你呼吁legendaxes

enter image description here

+0

添加axes_lst [1] .set_axis_off()只是plt.draw()之前,是我想要的。谢谢@tcaswell。 – Griff 2013-04-05 20:35:16

+1

我刚刚处理了你没有工作的部分;)。如果这解决了你的问题,你能接受吗? – tacaswell 2013-04-05 20:47:58