数据可视化之matplotlib实战:plt.pie() 绘制内嵌环形饼图
生活随笔
收集整理的這篇文章主要介紹了
数据可视化之matplotlib实战:plt.pie() 绘制内嵌环形饼图
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np# 防止亂碼
mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = Falseelements = ["面粉","砂糖","奶油","草莓醬","堅果"]weight1 = [40,15,20,10,15]
weight2 = [30,25,15,20,10]colormapList = ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00"]outer_colors = colormapList
inner_colors = colormapListwedges1,texts1,autotexts1 = plt.pie(weight1,autopct="%3.1f%%",radius=1,pctdistance=0.85,colors=outer_colors,textprops=dict(color="w"),wedgeprops=dict(width=0.3,edgecolor="w"))wedges2,texts2,autotexts2 = plt.pie(weight2,autopct="%3.1f%%",radius=0.7,pctdistance=0.75,colors=inner_colors,textprops=dict(color="w"),wedgeprops=dict(width=0.3,edgecolor="w"))plt.legend(wedges1,elements,fontsize=12,title="配料表",loc = "center_left",bbox_to_anchor=(0.91,0,0.3,1))plt.setp(autotexts1,size=12,weight = "bold")
plt.setp(autotexts2,size=12,weight = "bold")
plt.setp(texts1,size=10)plt.title("不同果醬面包配料比例表")plt.show()
總結
以上是生活随笔為你收集整理的数据可视化之matplotlib实战:plt.pie() 绘制内嵌环形饼图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redis的RDB与AOF持久化机制
- 下一篇: php记录访问者ip和次数,一个能对访问