# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
# 创建画布
plt.figure(figsize=(10, 10), dpi=50)
# 解决中文显示的问题
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['SimHei']
# 定义标题
plt.title('小奕')
# # 柱状图数据
x = [1, 2, 3, 4, 5, 6]
y = [100, 200, 300, 400, 500, 600]
y2 = [50, 100, 200, 300, 400, 500]
# # 画图
plt.bar(x, y, width=0.2, tick_label=[f'{i}月' for i in range(1, 7)], color='red', hatch='||||')
# # width: 定义柱状的宽度
# # tick_label:将x轴显示中文
# # color:指定柱状的颜色
# # hatch:柱状填充
# # 若需要画图多组数据,在x轴的值的基础上进行便宜(微量)
plt.bar([i+0.2 for i in x], y2, width=0.2, tick_label=[f'{i}月' for i in range(1, 7)], hatch='\\\\')
# 保存图片
plt.savefig('1.png')
plt.show()
02-19
4149
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交