Python 如何使matplotlib AutoCT成为标签名称的函数?
我有一个简单的Python饼图:Python 如何使matplotlib AutoCT成为标签名称的函数?,python,matplotlib,pie-chart,Python,Matplotlib,Pie Chart,我有一个简单的Python饼图: values = [3, 5, 12, 8] labels = ['a', 'b', 'c', 'd'] plt.pie(values, labels) 看起来像: dictionary = {'a': 0.31, 'b': 0.11, 'c' : 0.07, 'd': 0.12} labels = dictionary.keys() sizes = dictionary.values() fig1, ax1 = plt.subplots() ax1.pie(
values = [3, 5, 12, 8]
labels = ['a', 'b', 'c', 'd']
plt.pie(values, labels)
看起来像:
dictionary = {'a': 0.31, 'b': 0.11, 'c' : 0.07, 'd': 0.12}
labels = dictionary.keys()
sizes = dictionary.values()
fig1, ax1 = plt.subplots()
ax1.pie(sizes, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
plt.show()
我还有一本价值观词典:
dictionary = {'a': 0.31, 'b': 0.11, 'c' : 0.07, 'd': 0.12}
我想在字典中给每个片段加上相应的值。我该怎么做?我阅读了演示如何将额外参数传递给
autoct
函数的文章,但似乎每个切片的参数都必须相同,而在本例中,每个切片的参数都不同。我理解,您想要的是用dict中定义为值的饼图份额来标记每个片段,是这样吗
比如:
dictionary = {'a': 0.31, 'b': 0.11, 'c' : 0.07, 'd': 0.12}
labels = dictionary.keys()
sizes = dictionary.values()
fig1, ax1 = plt.subplots()
ax1.pie(sizes, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
plt.show()
希望这对您有用。值与
字典中的值有什么关联?它们只是保持字典
的浮点值近似比率的整数值吗?它们不相关。dictionary
中的值是标签名称的函数。您说它们不相关,然后接受了使用dictionary中的值绘制pi图的解决方案!!!我本想把标签贴在切片上,而不是贴在旁边,但我想这样就行了。