I am working on financial data, I intend to figure out how to create a nested pie chart on my data. Specifically, I filtered export and import product data and render nested plot for it. I did render pie chart for each, I am not able to get a correct nested pie chart or donut chart for the data. I looked into possible post on SO but didn't find any clue how to get my plot.
my current output:
import pandas as pd
from matplotlib import pyplot as plt
df5=df_from_gist_exp.groupby(['cty_ptn'])['qty1'].sum().nlargest(10)
df6=df_from_gist_imp.groupby(['cty_ptn'])['qty1'].sum().nlargest(10)
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.pie(df5, labels=df5.index, autopct='%1.0f%%', radius=1)
ax2.pie(df6, labels=df6.index, autopct='%1.0f%%', radius=1)
plt.axis('equal')
plt.tight_layout()
plt.show()
current plot:
I got this plot after running the above solution:
desired plot
actually I want to render this pie chart or donut chart using the same data:
How can I get this plot? Any trick to make this happen? Thanks



df_from_gistwithout considerable effort. Could you put this in a google colab or python notebook hosted on github? I am not familiar enough with matplotlib to solve this from memory. Good luck! - shanecandoitplt.text(0, 0, '960 K', fontsize=..., ha='center', va='bottom'). Experiment to find the best position for themetric tons. Positioning all the other texts is quite some work if you want a fully automated solution. Otherwise, just search for the best positions. - JohanCprint(df5.to_dict())and paste the result into your question. Same fordf6. Then remove all the other pandas and csv code, as they are not important for the pie diagram. Also add the output ofprint(df_export['qty1'].sum()), same for import. - JohanC