Python Don';t在子批次中显示标签
在下面的子图中,我希望在图例中显示标签;因此,我需要设置标签,但我不希望显示它们。也就是说,我只想要图例,我不希望在饼图旁边有标签名称。我该怎么做 这是我的密码:Python Don';t在子批次中显示标签,python,matplotlib,Python,Matplotlib,在下面的子图中,我希望在图例中显示标签;因此,我需要设置标签,但我不希望显示它们。也就是说,我只想要图例,我不希望在饼图旁边有标签名称。我该怎么做 这是我的密码: 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_lab
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()
产生:
如果不希望在单个饼图中显示标签,则不应在打印时调用标签,而应仅在定义图例时调用:
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()
这导致: