赞
踩
matplotlib.pyplot.table(cellText=None, cellColorss=None, cellLoc='right',
colWidths=None, rowLabels=None, rowColours=None,
rowLoc='left', colLabels=None, colColours=None,
colLoc='center', loc='bottom', bbox=None, edges='closed', **kwargs)
import matplotlib.pyplot as plt #导入模块 #显示中文 plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False # 绘制饼图 kinds = ['面粉', '全麦粉', '酵母', '苹果酱', '鸡蛋', '黄油', '盐', '白糖'] weight = [250, 150, 4, 250, 50, 30, 4, 20] plt.pie(weight, autopct='%3.1f%%') # 添加图例(通过bbox_to_anchor精细调整图例位置,nols调整列数) plt.legend(kinds, loc='upper right', bbox_to_anchor=[2.1, 0.7], ncols=4) # 添加表格(通过bbox精细调整表格位置和大小) plt.table(cellText=[weight], cellLoc='center', rowLabels=['重量(g)'], colLabels=kinds, rowColours=['pink'],colColours=['pink']*8, cellColours=[["pink"]*8], bbox=[1.2,0.3,0.8,0.2]) plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。