python-Matplotlib绘制分列式饼图并添加表格
import matplotlib.pyplot as plt
import numpy as np
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=["red","blue","green","pink"]
explode=(0.1,0.1,0.1,0.1)
#exploded pie chart
plt.pie(students,explode=explode,labels=labels,
startangle=45,shadow=True,
colors=colors,autopct="%3.1f%%")
plt.title("选择不同难度测试试卷的学生百分比",fontsize=20)
col_labels = ['col1','col2','col3']
row_labels = ['row1','row2']
table_vals = [[11,12,13],[21,22,23]]
row_colors = ['red','gold','green']
plt.table(cellText=table_vals,colWidths=[0.1]*3,
rowLabels=row_labels,colLabels=col_labels,
rowColours=row_colors,colColours=row_colors,
loc="bottom")
plt.show()