【发布时间】:2021-07-13 07:32:24
【问题描述】:
作为 to_show=['A','B','C','D','E'] 你好,我想用一些字符串值填充饼图的扇区,如 A、B、C、D、E autopct 是一个函数,但我不知道在饼图扇区中显示并隐藏自动生成的 %ages 值的确切方法。
【问题讨论】:
标签: python matplotlib pie-chart
作为 to_show=['A','B','C','D','E'] 你好,我想用一些字符串值填充饼图的扇区,如 A、B、C、D、E autopct 是一个函数,但我不知道在饼图扇区中显示并隐藏自动生成的 %ages 值的确切方法。
【问题讨论】:
标签: python matplotlib pie-chart
import matplotlib.pyplot as plt # make the pie circular by setting the aspect ratio to 1
plt.figure(figsize=plt.figaspect(1))
index = [1, 2, 3, 4]
values = [1, 2, 3, 4]
labels = ['a', 'b', 'c', 'd']
cutom_labels = ['1', '2,3', '4,5', '6']
num = -1
plt.pie(values, labels=cutom_labels,labeldistance=0.5)
plt.pie(values, labels=labels)
plt.show()`
【讨论】:
【讨论】:
import matplotlib.pyplot as plt # make the pie circular by setting the aspect ratio to 1 plt.figure(figsize=plt.figaspect(1)) index = [1, 2, 3, 4] values = [1, 2, 3, 4] labels = ['a', 'b', 'c', 'd'] cutom_labels = ['1', '2,3', '4,5', '6'] num = -1 def make_autopct(values): def my_autopct(pct): return cutom_labels[2] return my_autopct plt.pie(values, labels=labels, autopct=make_autopct(values)) plt.show() 更改每个部门的值