我想并排放置 2 个圆环图,目前,我并排放置一个饼图和圆环图。甜甜圈图这是我的代码,我需要一个循环吗?recipe = "flour","sugar","egg","butter","milk","yeast"fracs = [15, 30, 45, 10]data = [225, 90, 50, 60, 100, 5]fig = plt.figure()ax1 = fig.add_axes([0, 0, .5, .5], aspect=1)ax1.pie(data, labels=recipe, radius = 1.2)ax2 = fig.add_axes([.5, .0, .5, .5], aspect=1)ax2.pie(data, labels=recipe, radius = 1.2)circle = plt.Circle((0,0), 0.7, color='white')p=plt.gcf()p.gca().add_artist(circle)ax1.set_title('A donut', y=1.1)ax2.set_title('A donut',y=1.1)plt.savefig('donut1.png')plt.show()
2 回答
神不在的星期二
TA贡献1963条经验 获得超6个赞
您可以使用 中的wedgeprops参数定义甜甜圈pie。
inner_radius = 0.7
chart_radius = 1.2
wedge_props = dict(width=chart_radius-inner_radius)
ax1.pie(data, labels=recipe, radius=chart_radius, wedgeprops=wedge_props)
ax2.pie(data, labels=recipe, radius=chart_radius, wedgeprops=wedge_props)
添加回答
举报
0/150
提交
取消