我正在寻找类似下面的内容,以便使用matplotlib python
数据如下:
类别值平均值
0 a 1.0 0.7
1 b 0.1 0.2
这是到目前为止我拥有的一种解决方法的代码:
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()