Files
smart-management-auto-test/zhyy/library/CommonFun/drawPicture.py
qiaoxinjiu 6994b185a3 addproject
2026-01-22 19:10:37 +08:00

31 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import matplotlib.pyplot as plt
import matplotlib
# 设置字体为支持中文的字体如SimHei
matplotlib.rcParams['font.sans-serif'] = ['SimHei'] # Windows系统
# matplotlib.rcParams['font.sans-serif'] = ['Arial Unicode MS'] # macOS系统
matplotlib.rcParams['axes.unicode_minus'] = False # 解决负号显示问题
# 数据
categories = ['供应链', '天窗', 'cc', 'la', '题库', '练测', '教务', '教师', '基础', '学生端', '家长端', '活字', '转介绍']
values = [8, 4, 13, 20, 11, 2, 22, 10, 1, 1, 14, 1, 17]
# 创建柱状图
plt.figure(figsize=(10, 6))
bars = plt.bar(categories, values, color='skyblue')
# 添加标题和标签
plt.title('各类别数量统计', fontsize=16)
plt.xlabel('类别', fontsize=12)
plt.ylabel('数量', fontsize=12)
plt.xticks(rotation=45, ha='right') # 旋转X轴标签
# 在每个柱子上方显示数量
for bar in bars:
height = bar.get_height()
plt.text(bar.get_x() + bar.get_width() / 2, height, str(height),
ha='center', va='bottom', fontsize=10)
# 显示图表
plt.tight_layout()
plt.show()