autopct enables you to display the percent value using Python string formatting. For example, if autopct='%.2f', then for each pie wedge, the format string is '%.2f' and the numerical percent value for that wedge is pct, so the wedge label is set to the string '%.2f'%pct
小插曲英文学习 enables sb to do something 使用某物具有某种能力做某种事情
cars = ['AUDI', 'BMW', 'FORD',
'TESLA', 'JAGUAR', 'MERCEDES'
]
explode = (0.1, 0.0, 0.2, 0.3, 0.0, 0.0)
colors = ( "orange", "cyan", "brown",
"grey", "indigo",
"beige" )
data = [23, 17, 35, 29, 12, 41]
wp = { 'linewidth' : 1, 'edgecolor' : "green" }
def func(pct, allvalues):
print(pct)
absolute = int(pct / 100.*np.sum(allvalues))
val = "{:.1f}%
({:d} g)".format(pct, absolute)
return val
fig, ax = plt.subplots(figsize =(10, 7))
wedges, texts, autotexts = ax.pie(data,
autopct = lambda pct: func(pct, data),
explode = explode,
labels = cars,
shadow = True,
colors = colors,
startangle = 90,
wedgeprops = wp,
textprops =
dict(color ="magenta"))
更新时间:2024-11-01
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号