赞
踩
import matplotlib.pyplot as plt # make the pie circular by setting the aspect ratio to 1 # plt.figure(figsize=plt.figaspect(1)) values = [3, 12, 5, 8] labels = ['a', 'b', 'c', 'd'] def make_autopct(values): def my_autopct(pct): total = sum(values) val = int(round(pct*total/100.0)) # 同时显示数值和占比的饼图 return '{p:.2f}% ({v:d})'.format(p=pct,v=val) return my_autopct plt.pie(values, labels=labels, autopct=make_autopct(values)) plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。