python三个并排饼图

import matplotlib.pyplot as plt

labels = 'Comments rated 1', 'Comments rated 2', 'Comments rated 3', 'Comments rated 4', 'Comments rated 5'
sizes = [38, 16, 18, 54, 107]
sizes1 = [84, 45, 59, 132, 314]
sizes2 = [205, 172, 273, 561, 1954]
explode = (0, 0, 0, 0, 0.025)  # 设置各部分距离圆心的距离
fig1 = plt.figure(facecolor='white',figsize=(16,8))
ax1=plt.subplot(1,3,1)
ax1.pie(sizes, explode=explode,autopct='%1.1f%%',
        shadow=False, startangle=90)
ax1.axis('equal')
ax1.legend(labels)

ax1=plt.subplot(1,3,2)
ax1.pie(sizes1, explode=explode,autopct='%1.1f%%',
        shadow=False, startangle=90)
ax1.axis('equal')
ax1.legend(labels)

ax1=plt.subplot(1,3,3)
ax1.pie(sizes2, explode=explode,autopct='%1.1f%%',
        shadow=False, startangle=90)
ax1.axis('equal')
ax1.legend(labels)

plt.tight_layout()
plt.show()
fig1.savefig('饼状图.jpg',dpi=400)

运行效果如下:
python三个并排饼图_第1张图片

你可能感兴趣的:(matplotlib)