并排的圆环图

我想并排放置 2 个圆环图,目前,我并排放置一个饼图和圆环图。

甜甜圈图

http://img2.mukewang.com/6164f85b000105cc04320283.jpg

这是我的代码,我需要一个循环吗?


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()


青春有我
浏览 184回答 2
2回答

神不在的星期二

您可以使用 中的wedgeprops参数定义甜甜圈pie。inner_radius = 0.7chart_radius = 1.2wedge_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)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python