绘制食材饼图

import matplotlib.pyplot as plt

导入matplotlib库

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, labels=kinds, autopct='%3.1f%%')
plt.title('食材配比')  # 设置标题
# 将图例放在饼图的右侧,分为四列
plt.legend(loc='upper center', bbox_to_anchor=(1.6, 0.6), ncol=4)
# 创建表格
table_data = [weight]
row_labels = ['重量(g)']
col_labels = kinds
 
#循环遍历每个单元格,并设置其背景色为蓝色
colors = [['blue' for _ in range(len(kinds))] for _ in range(len(row_labels))]
table = plt.table(cellText=table_data, cellLoc='center', rowLabels=row_labels, colLabels=col_labels, loc='bottom right',cellColours=colors, colWidths=[0.1] * len(col_labels))
# 设置表格单元格的背景色为蓝色
for cell in table.get_celld().values():
    cell.set_facecolor('blue')
 
table.auto_set_font_size(False)  # 关闭自动调整字体大小
table.set_fontsize(9)  # 设置表格字体大小
table.scale(1, 2)  # 调整表格的整体缩放比例,使表格高度增加一倍
 
plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值