addproject
This commit is contained in:
31
zhyy/library/CommonFun/drawPicture.py
Normal file
31
zhyy/library/CommonFun/drawPicture.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user