生源质量——python 可视化(plt 多维度 柱状图)

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']#设置字体以便支持中文
 
 
def show():
    total_Score=[852.5, 746.7, 649.2, 625.9, 566.1, 556.7, 526.4, 497.7, 488.0, 457.2]
    matriculate_Quality=[852.5, 746.7, 649.2, 625.9, 566.1, 556.7, 526.4, 497.7, 488.0, 457.2]
    college_Name=['清华大学', '北京大学', '浙江大学', '上海交通大学', '南京大学', '复旦大学', '中国科学技术大学', '华中科技大学', '武汉大学', '中山大学']
    year=[2015]
    ind = np.arange(len(total_Score))
    width = 0.35
    fig, ax = plt.subplots()
    rects1 = ax.bar(ind - width / 2, total_Score, width, yerr=None, color="SkyBlue", label="总分")
    rects2 = ax.bar(ind + width / 2, matriculate_Quality, width, yerr=None, color="IndianRed", label="生源质量")
 
    ax.set_ylabel("分值")
    ax.set_title(str(year) + "年中国最好大学分数指标")
    ax.set_xticks(ind)
    ax.set_xticklabels(college_Name, rotation=20)
    ax.legend()
 
    def autolabel(rects, xpos='center'):
        xpos = xpos.lower()
        ha = {'center': 'center', 'right': 'left', 'left': 'right'}
        offset = {'center': 0.5, 'right': 0.57, 'left': 0.43}
 
        for rect in rects:
            height = rect.get_height()
            ax.text(rect.get_x() + rect.get_width() * offset[xpos], 1.01 * height,
                    '{}'.format(height), ha=ha[xpos], va='bottom')
 
    autolabel(rects1, "left")
    autolabel(rects2, "right")
 
    plt.show()
show()

  

posted @   博二爷  阅读(386)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示