1. 程式人生 > >python可視化---向餅圖中添加表格

python可視化---向餅圖中添加表格

難度 nts color font values 技術 學生 text value

import matplotlib.pyplot as plt
import matplotlib 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("選擇不同難度測試試卷的學生百分比") # 像餅圖中添加表格 colLabels = ["A難度水平", "B難度水平", "C難度水平", "D難度水平"] rowLabels = ["學生選擇試卷人數"] studentValues = [[350, 150, 200, 300]] colColors
= ["#377eb8", "#4daf4a", "#984ea3", "#ff7f00"] plt.table(cellText=studentValues, cellLoc="center", colWidths=[0.1]*4, colLabels=colLabels, colColours=colColors, rowLabels=rowLabels, rowLoc="center", loc="bottom") plt.show()

技術分享圖片

python可視化---向餅圖中添加表格