天天看點

python 可視化餅圖_python可視化---餅圖

importmatplotlib.pyplot as pltimportmatplotlib as mpl

mpl.rcParams["font.sans-serif"] = ["SimHei"]

mpl.rcParams["axes.unicode_minus"] =False

labels= "A難度水準", "B難度水準", "C難度水準", "D難度水準"students= [0.35, 0.15, 0.20, 0.30]

colors= ["#377eb8", "#4daf4a", "#984ea3", "#ff7f00"]

explode= (0.1, 0.1, 0.1, 0.1)

plt.pie(students, explode=explode, labels=labels, autopct="%3.1f%%",

startangle=45, shadow=True, colors=colors)

plt.title("選擇不同難度測試試卷的學生百分比")

plt.show()