2014-04-08 134 views
1

在下面的子图中,我想让标签显示在图例中;因此,我需要设置标签,但我不希望它们显示。也就是说,我只需要图例,我不希望标签名称在我的饼图旁边。我怎样才能做到这一点?不要在子图中显示标签

这里是我的代码:

my_labels = ['food', 'music', 'clothes'] 

fig = pylab.figure() 
fig.text(0.4,0.95,"Consumption by Region") 

ax1 = fig.add_subplot(2,2,1) 
ax1.pie([1,2,3], labels = my_labels) 
ax1.text(0.6, 1, "North West") 

ax2 = fig.add_subplot(2,2,2) 
ax2.pie([6,4,3], labels = my_labels) 
ax2.text(0.6, 1, "North East") 

ax3 = fig.add_subplot(2,2,3) 
ax3.pie([1,4,3], labels = my_labels) 
ax3.text(0.6, 1, "South West") 

ax4 = fig.add_subplot(2,2,4) 
ax4.pie([9,1,3], labels = my_labels) 
ax4.text(0.6, 1, "South East") 

pylab.legend(title="Legend", loc=(-1.5,0.9)) 

pylab.show() 

主要生产:

enter image description here

回答

3

如果你不希望他们在各个饼图,标签不应该在被叫但仅限定义图例时:

import pylab 

my_labels = ['food', 'music', 'clothes'] 

fig = pylab.figure() 
fig.text(0.4,0.95,"Consumption by Region") 

ax1 = fig.add_subplot(2,2,1) 
ax1.pie([1,2,3]) 
ax1.text(0.6, 1, "North West") 

ax2 = fig.add_subplot(2,2,2) 
ax2.pie([6,4,3]) 
ax2.text(0.6, 1, "North East") 

ax3 = fig.add_subplot(2,2,3) 
ax3.pie([1,4,3]) 
ax3.text(0.6, 1, "South West") 

ax4 = fig.add_subplot(2,2,4) 
ax4.pie([9,1,3]) 
ax4.text(0.6, 1, "South East") 

pylab.legend(my_labels, title="Legend", loc=(-1.5,0.9)) 

pylab.show() 

This res ults:

enter image description here

+0

完美。谢谢。 – Akavall

+0

不客气。 –