'Plotting subplots of dataframe with subplots of piecharts or nested pie chart with Pandas and Matplotlib
Hi my dataframe looks like the followig format and is named immunizations_df:
I'm trying to plot a subplot of piecharts, each piechart symbols the number of values of each CODE (I have 18 different codes) on each decade. Before relating to the decade column i plotted a piechart of the total number of values of each codes in all of my dataset:
Using the following code:
total_immunizations_by_decade = immunizations_df["DECADE"].value_counts()
total_immunizations_by_decade.plot(kind='pie')
First, I tried the following code in order to subplot 9 piecharts for each decade:
decades_unique = immunizations_df.DECADE.unique().tolist()
plt.figure(figsize=(30,5))
plt.subplots_adjust(hspace=0.5)
plt.suptitle("Decade's type of immunizations histogram")
for n, decade in enumerate(decades_unique):
ax = plt.subplot(9,1,n+1)
immunizations_df.loc[immunizations_df["DECADE"] == decade]["CODE"].plot(ax=ax, kind='pie')
ax.set_title(decade)
plt.show()
and got the following unclear figure:
Can someone help me understand how to enlarge the figure or maybe create the subplots in a better way, i also tried a nested pie chart and didn't succeed (maybe its the right way to plot).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|