One figure to present multiple pie chart with different size


enter image description here

The figure above is an illustration of my purpose.

It's easy to plot pie chart in MatPlotLib.

But how to draw several pie in one figure and the size of each figure depend on the value I set.

Any advices or recommandation is appreciate!


Answers:


You can use subplots to place the pies into the figure. You can then use the radius argument to determine their size. As usual it helps to consult the manual.

Here is an example:

import matplotlib.pyplot as plt
import numpy as np; np.random.seed(1)

t = "Plot a pie chart  with different sized pies all in one figure"
X  = np.random.rand(12,4)*30
r = np.random.rand(12)*0.8+0.6

fig, axes= plt.subplots(3, 4)

for i, ax in enumerate(axes.flatten()):
    x = X[i,:]/np.sum(X[i,:])
    ax.pie(x, radius = r[i], autopct="%.1f%%", pctdistance=0.9)
    ax.set_title(t.split()[i])

plt.show()

enter image description here