python 饼图_python学习之matplotlib绘制内嵌环形饼图

直接上代码:

import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["font.sans-serif"]=["SimHei"]
plt.rcParams["axes.unicode_minus"]=False
labels=['A','B','C','D','其他']
A1=[40,25,20,5,10]
A2=[20,35,15,18,12]
color=['r','g','b','lightblue','lightgreen']
wedges1,texts1,autotexts1=plt.pie(A1,
autopct='%3.1f%%',
radius=1,
pctdistance=0.8,
colors=color,
startangle=180,
textprops=dict(color='w'),
wedgeprops=dict(width=0.4,edgecolor='w'))
wedges2,texts2,autotexts2=plt.pie(A2,
autopct='%4.1f%%',
radius=0.6,
pctdistance=0.7,
colors=color,
startangle=180,
textprops=dict(color='w'),
wedgeprops=dict(width=0.4, edgecolor='w'))
plt.legend(wedges1,
labels,
fontsize=12,
title='配方列表',
loc='center right',
bbox_to_anchor=(0.91,0,0.3,1))
plt.setp(autotexts1,size=15,weight='bold')
plt.setp(autotexts2,size=15,weight='bold')
plt.setp(texts1,size=12)
plt.title('面包生产配方')
plt.show()

运行结果:

python 饼图_python学习之matplotlib绘制内嵌环形饼图_第1张图片

你可能感兴趣的:(python,饼图)