Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Don';t在子批次中显示标签_Python_Matplotlib - Fatal编程技术网

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()
这导致: