python100天 62 pie 函数画饼图全景效果

下面是一个pie函数几乎所有参数的设置后的一个效果


如何查看效果

autopack 参数有点意思

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

标签:函数   全景   效果   比值   英文   百分比   总和   字符串   线条   参数   能力

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top