1 #导入模块、并显示中文以及符号 import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False 2 #准备数据 kinds = ['面粉', '全麦粉', '酵母', '苹果酱', '鸡蛋', '黄油', '盐', '白糖'] weight = [250, 150, 4, 250, 50, 30, 4, 20] 3 #绘制饼图 plt.pie(weight, autopct='%3.1f%%') 4 #添加图例 matplotlib.pyplot.legend(*args,**kwargs) plt.legend(kinds, loc='upper right', bbox_to_anchor=[1.3, 1.1],ncol=4) 5 #添加表格 #语法: matplotlib.pyplot.table(cellText=None, cellColours=None, cellLoc='right', colWidths=None, rowLabels=None, rowColours=None, rowLoc='left', colLabels=None, colColours=None, colLoc='center', loc='bottom', bbox=None, edges='closed', **kwargs) plt.table(cellText=[weight], cellLoc='center', rowLabels=['重量(g)'], colLabels=kinds,loc='bottom',rowColours='m', colColours=('#98F5FF','#8EE5EE','#7AC5CD','#53868B','#00F5FF','#00E5EE','#00C5CD','#00868B'), cellColours=[['#FFFAF0','#FDF5E6','#FAF0E6','#FAEBD7','#FFEFD5','#FFEBCD','#FFE4C4','#FFDAB9']]) #展示图表 plt.show()