0

I am looking for something like below to plot using matplotlib python

Here's how the data looks like:

Category Values Average

0 a 1.0 0.7

1 b 0.1 0.2

I wanted to print two donuts like below- enter image description here

Here is the code I have till now with one workaround:

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()
Manish Singla
  • 381
  • 1
  • 4
  • 11
  • 1
    What you are looking for is a sunburst chart I believe? https://stackoverflow.com/questions/12926779/how-to-make-a-sunburst-plot-in-r-or-python This might be helpful. – Nihal Sangeeth Mar 11 '19 at 07:32
  • @NihalSangeeth I just need one wedge in each donut which need not to be in a ratio of innermost 100% circle. – Manish Singla Mar 11 '19 at 09:12

0 Answers0