7
我正在根据matplotlib-demo创建饼图:http://matplotlib.org/examples/pylab_examples/pie_demo.html
每个压裂的百分比似乎都是自动标记的。我怎样才能用来自压裂[]的绝对值来代替在饼图上绘制的自动标记的相对值(%)?Matplotlib饼图:如何用绝对值替换自动标记的相对值
我正在根据matplotlib-demo创建饼图:http://matplotlib.org/examples/pylab_examples/pie_demo.html
每个压裂的百分比似乎都是自动标记的。我怎样才能用来自压裂[]的绝对值来代替在饼图上绘制的自动标记的相对值(%)?Matplotlib饼图:如何用绝对值替换自动标记的相对值
help(pie)
说:
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]
total = sum(fracs)
explode=(0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels,
autopct=lambda(p): '{:.0f}'.format(p * total/100),
shadow=True, startangle=90)
show()
要:
,所以你可以通过饼图的总规模乘以除以100转百分比回原始值显示百分比和总数:http://stackoverflow.com/questions/6170246/how-do-i-use-matplotlib-autopct – zehpunktbarron
这应该是'lambda p'在该代码中,没有括号。 –
@ K.-MichaelAye:Python 2.7中的括号是合法的 - 注意答案的写日期。 –