答案 0 :(得分:4)
您可以使用add_axes
调整绘图的轴大小。也,
radius
函数中有一个pie
参数,您可以使用该参数指定饼图的半径。检查以下代码:
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]
fig = plt.figure()
ax1 = fig.add_axes([.1, .1, .8, .8], aspect=1)
ax1.pie(fracs, labels=labels)
ax2 = fig.add_axes([.65, .65, .3, .3], aspect=1) # You can adjust the position and size of the axes for the pie plot
ax2.pie(fracs, labels=labels, radius=.8) # The radius argument can also be used to adjust the size of the pie plot
plt.show()
答案 1 :(得分:4)
您可以使用子图将馅饼放入图中。然后,您可以使用radius
参数来确定其大小。像往常一样,有助于咨询the manual。
以下是一个例子:
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()