I have dataframe with 3 columns like:
> A B C
red yes 100
red no 25
blue yes 200
blue no 20
green yes 40
green no 10
yellow yes 40
yellow no 20
I would like to make a pie chart for each answer at column B by column A and give the same color at the part than the label which it assigned.
For example, I would like the color red for the part on pie chart assign at red label, blue for blue, etc. Sometimes the label couldn't be a colour but I want to choose the color to assign at that label.
EXPECTED OUTPOUT:
I tried this code:
import pandas as pd
import matplotlib.pyplot as plt
df_bis = df.groupby(['A','B'], axis = 0).agg('count')
df_bis['C'].plot(kind='pie',
figsize=(5,4),
subplots=True,
autopct='%1.1f%%', # add in percentages
startangle=90, # start angle 90°
shadow=True, # add shadow
colors =
{'red':"red",'blue':"blue",'yellow':"gold",'green':"green"}
)
plt.axis('equal') # Sets the pie chart to look like a circle.
But it doesn't work.
Have you an idea to make that? Thanks