Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a multilevel pie chart where outer circle is subset of inner circle in matplotlib

I have seen many ways for creating a multi-level pie chart where inner circle is subset of outer circle, however, I am trying to create a chart like this in matplotlib. enter image description here

How can I create a chart like above in python using matplotlib?

like image 987
Awais Hussain Avatar asked Oct 16 '25 11:10

Awais Hussain


1 Answers

import matplotlib.pyplot as plt
import numpy as np    

fig, ax = plt.subplots()

size = 0.3
vals = np.array([[60., 32.], [37., 40.], [29., 10.]])

cmap = plt.get_cmap("tab20c")
outer_colors = cmap(np.arange(3)*4)
inner_colors = cmap([1, 2, 5, 6, 9, 10])

ax.pie(vals.sum(axis=1), radius=3-0.9, colors=outer_colors,
       wedgeprops=dict(width=0.9, edgecolor='w'),labels=["Europe","North America","Scandiavia"],
       pctdistance=1.1, labeldistance=0.65)

ax.pie(vals.flatten(), radius=3, colors=inner_colors,
       wedgeprops=dict(width=0.9, edgecolor='w'),labels=["Germany","France","USA","Mexico","Finland","Sweden"],
       pctdistance=1.1, labeldistance=0.85)

ax.set(aspect="equal", title='')
plt.show()

enter image description here

Referance : https://matplotlib.org/stable/gallery/pie_and_polar_charts/nested_pie.html

You can adjust some parameters like radius,width,colors, labeldistance.

like image 86
G.Young Avatar answered Oct 19 '25 02:10

G.Young