Han*_*gzu 5 python visualization matplotlib
上图说明了我的目的。
在MatPlotLib中绘制饼图很容易。
但是如何在一个图形中绘制多个饼图以及每个图形的大小取决于我设置的值。
任何建议或建议,不胜感激!
您可以使用子图将饼图放入图中。然后您可以使用该radius参数来确定它们的大小。像往常一样,查阅手册会有所帮助。
下面是一个例子:
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()
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以使用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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3529 次 |
| 最近记录: |