馅饼里面的馅饼|具有avg值的甜甜圈图python matplotlib

时间:2019-03-11 07:27:57

标签: python matplotlib visualization pie-chart donut-chart

我正在寻找类似下面的内容,以便使用matplotlib python

数据如下:

类别值平均值

0 a 1.0 0.7

1 b 0.1 0.2

我想打印两个像下面的甜甜圈- enter image description here

这是到目前为止我拥有的一种解决方法的代码:

enter code here

# Viz 4: code for Stacked pie chart
import pandas as pd
import matplotlib.pyplot as plt
data=[['a',1,0.7],['b',0.3,0.2]]
df_chart4=pd.DataFrame(data,columns=['category','values','average'])

group_names=['a']
group_size=df_chart4[df_chart4['category']=='a']['values'].tolist()
group_colors=[ 'green']
# print(group_size)

fig, ax = plt.subplots()
ax.axis('equal') 

ax.pie(group_size,labels=group_names, radius=1.0, labeldistance=1.1,pctdistance =0.82,
                  colors=group_colors,startangle=90,autopct=str(group_size[0]))


#second ring
subgroup_names=[ 'b','']
subgroup_size=df_chart4[df_chart4['category']=='b']['values'].tolist()
subgroup_size.append(1-subgroup_size[0])
subgroup_colors=[ 'orange','white']
mypie2=ax.pie(subgroup_size,labels=subgroup_names, radius=0.7, labeldistance=0.2,pctdistance =0.72,
                  colors=subgroup_colors,startangle=90,autopct=str(subgroup_size[0]))
centre_circle = plt.Circle((0,0),0.40,fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)

plt.tight_layout()
plt.show()

0 个答案:

没有答案