我希望使用matplotlib创建的饼图能够显示实际值,而不仅仅是百分比。以下是我的代码:
pie_shares= [i for i in mean.values()]
positions = [i for i in mean.keys()]
plt.pie(pie_shares,labels=positions, autopct='%1.1f%%', )
plt.show()
我希望使用matplotlib创建的饼图能够显示实际值,而不仅仅是百分比。以下是我的代码:
pie_shares= [i for i in mean.values()]
positions = [i for i in mean.keys()]
plt.pie(pie_shares,labels=positions, autopct='%1.1f%%', )
plt.show()
如果您想显示饼图切片的实际值,您必须将这些值提供给标签:
def autopct_format(values):
def my_format(pct):
total = sum(values)
val = int(round(pct*total/100.0))
return '{v:d}'.format(v=val)
return my_format
plt.pie(pie_shares, labels = positions, autopct = autopct_format(pie_shares))
return '{v:,}'.format(v=val)
,... - Martin Dvorak