python实现成绩分析并实现可视化

写在前面

小班的高数段考成绩出来了,惨不忍睹,于是我想可视化看看到底有多惨…

代码有点凌乱,因为直接在Jupyter上想到啥就瞎敲的啥,以下也是ipynb文件直接转换过来的,(抽空整理了一下,前面的两大点 后面就不用了)

转换代码(在cmd里执行就可):

jupyter nbconvert --to markdown 成绩分析.ipynb

----------我是分割线-----------(更新)

导入成绩

num = [67,73,66,21,58,61,41,75,69,68,54,49,60,79,61,30,76,69,67,24,82,61,40,71,80,77,82,60,87,71,69,81,69,61,67,0,71]

先进行数据处理

from collections import Counter
# 将成绩统计,统计每个分数的人数
cnt = Counter(num)
print("每个分数人数显示:",cnt)

# 将统计的分数段进行排序,在排序之前,我们可以观察到Counter的结果,所以我只能想到先用两个list来分开存,再关联排序
x = []
y = []

# 对分数段进行以5为单位的划分统计
cf = [0 for i in range(0,20)]
# 10
cn = [0 for i in range(0,10)]

for i,j in cnt.items():
    x.append(i)
    y.append(j)
    
    # 对结果进行统计,之后可视化更加清晰
    cf[(int)(i/5)] +=j;
    # 10
    cn[(int)(i/10)]+=j;

# 对x,y进行关联排序
x,y = zip(*sorted(zip(x,y)))

# 对有成绩的分数段进行展示
print('以5为单位的分数段为:\n')
for i in range(20):
    if(cf[i]!=0):
        print(i*5,'~',(i+1)*5-1,':',cf[i])
每个分数人数显示: Counter({61: 4, 69: 4, 67: 3, 71: 3, 60: 2, 82: 2, 73: 1, 66: 1, 21: 1, 58: 1, 41: 1, 75: 1, 68: 1, 54: 1, 49: 1, 79: 1, 30: 1, 76: 1, 24: 1, 40: 1, 80: 1, 77: 1, 87: 1, 81: 1, 0: 1})
以5为单位的分数段为:

0 ~ 4 : 1
20 ~ 24 : 2
30 ~ 34 : 1
40 ~ 44 : 2
45 ~ 49 : 1
50 ~ 54 : 1
55 ~ 59 : 1
60 ~ 64 : 6
65 ~ 69 : 9
70 ~ 74 : 4
75 ~ 79 : 4
80 ~ 84 : 4
85 ~ 89 : 1

开始可视化

# 开始可视化
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.pyplot import MultipleLocator
import re

# 先将普通的成绩绘制一个普通的柱状图
# 横坐标是成绩,纵坐标是每个成绩的人数
plt.bar(x,y)
plt.figure()
plt.show()

# 但是可以看出这个结果非常的不好看,于是可以用到上一步做的以5为单位的数据,并且把柱状图美化一下
# 此时我们首先需要增加一个纵坐标
yi = np.arange(0,100,5)

# 设置横纵坐标的间隔,横坐标间隔为10,纵坐标为1
x_major_locator=MultipleLocator(10)
y_major_locator=MultipleLocator(1)

#ax为两条坐标轴的实例
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
# 设置横纵坐标的范围
plt.xlim(0,100)
plt.ylim(0,10)

# 柱状图的设置,其中比较重要的是width,显示宽度,会比较好看一点,还有柱体的颜色,如果有多个不同的数据可以区分
plt.bar(yi,cf, alpha=0.9, width = 5, facecolor = 'yellowgreen', edgecolor = 'white', label='one', lw=1)
plt.show()

# 普通折线图,效果已经可以看出来了
plt.plot(yi,cf)
plt.show()

# 再稍微细分一下,使用的横纵坐标和上同
x_major_locator=MultipleLocator(10)
y_major_locator=MultipleLocator(1)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.xlim(0,100)
plt.ylim(0,10)

plt.title('成绩段分布图')
plt.xlabel('分数')
plt.ylabel('人数')

plt.plot(yi,cf)
plt.show()

在这里插入图片描述

<matplotlib.figure.Figure at 0x7fe1839a7240>
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

分割线,下面都是草稿都不用看辽

from collections import Counter
cnt = Counter(num)
print(cnt)
Counter({61: 4, 69: 4, 67: 3, 71: 3, 60: 2, 82: 2, 73: 1, 66: 1, 21: 1, 58: 1, 41: 1, 75: 1, 68: 1, 54: 1, 49: 1, 79: 1, 30: 1, 76: 1, 24: 1, 40: 1, 80: 1, 77: 1, 87: 1, 81: 1, 0: 1})
lenn = len(cnt)
print(lenn)
25
# print(cnt.self)
# print(cnt.args)

分数段展示(以5为单位)

import matplotlib.pyplot as plt
import re
x = []
y = []
un = 0
s = 0
se = 0
ei = 0
ni = 0
ccc = [0,0,0,0,0,0,0,0,0,0,0]
cf = [0 for i in range(0,20)]
for i,j in cnt.items():
    # print(i,j)
    
    x.append(i)
    y.append(j)
    
    # print(i,":",j)
    
    ccc[(int)(i/10)] += j;
    cf[(int)(i/5)] +=j;
for i in range(20):
    if(cf[i]!=0):
        print(i*5,'~',(i+1)*5-1,':',cf[i])
    # if(i<60): un = un + j
    # elif(i<70): s = s + j
    # elif(i<80): se = se + j
    # elif(i<90): ei = ei + j
# print("60分以下人数:",un,"\n60~69分人数:",s,"\n70~79分人数:",se,"\n80~89分人数:",ei,"\n90分以上人数:",ni)    
0 ~ 4 : 1
20 ~ 24 : 2
30 ~ 34 : 1
40 ~ 44 : 2
45 ~ 49 : 1
50 ~ 54 : 1
55 ~ 59 : 1
60 ~ 64 : 6
65 ~ 69 : 9
70 ~ 74 : 4
75 ~ 79 : 4
80 ~ 84 : 4
85 ~ 89 : 1

设置表格的横纵坐标范围

x_major_locator=MultipleLocator(10)
y_major_locator=MultipleLocator(1)

ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.xlim(0,100)
plt.ylim(0,10)
plt.bar(x,y)
plt.figure()
plt.show()

plt.bar(yi,ccc)
plt.figure()
plt.show()

x_major_locator=MultipleLocator(10)
y_major_locator=MultipleLocator(1)

#ax为两条坐标轴的实例
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.xlim(0,100)
plt.ylim(0,10)

plt.bar(yii,cf, alpha=0.9, width = 5, facecolor = 'yellowgreen', edgecolor = 'white', label='one', lw=1)
plt.show()

在这里插入图片描述
<Figure size 432x288 with 0 Axes>
在这里插入图片描述
<Figure size 432x288 with 0 Axes>
在这里插入图片描述

具体人数显示

import numpy as np
yi = [0,10,20,30,40,50,60,70,80,90,100]
plt.plot(yi,ccc)
plt.show()

yii = np.arange(0,100,5)

print(yii)

plt.plot(yii,cf)
plt.show()

x,y=zip(*sorted(zip(x,y)))
for i in range(lenn):
    print(x[i],":",y[i])

在这里插入图片描述

[ 0  5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95]

在这里插入图片描述

0 : 1
21 : 1
24 : 1
30 : 1
40 : 1
41 : 1
49 : 1
54 : 1
58 : 1
60 : 2
61 : 4
66 : 1
67 : 3
68 : 1
69 : 4
71 : 3
73 : 1
75 : 1
76 : 1
77 : 1
79 : 1
80 : 1
81 : 1
82 : 2
87 : 1

成绩段分布图

from matplotlib.pyplot import MultipleLocator
x,y = zip(*sorted(zip(x,y)))
x_major_locator=MultipleLocator(10)
y_major_locator=MultipleLocator(1)
ax=plt.gca()
#ax为两条坐标轴的实例
ax.xaxis.set_major_locator(x_major_locator)
#把x轴的主刻度设置为1的倍数
ax.yaxis.set_major_locator(y_major_locator)
#把y轴的主刻度设置为10的倍数

# plt.plot(x,y)
plt.title('成绩段分布图')
plt.xlabel('分数')
plt.ylabel('人数')
plt.plot(yii,cf)
# plt.plot(x,y)

plt.xlim(0,100)
plt.ylim(0,10)

plt.show()

在这里插入图片描述

flag = 0
fullx = []
fully = []
for i,j in cnt.items():
    if(flag < i):
        for number in range(i-flag,3):
            fullx.append(flag+number)
            fully.append(0)
        fullx.append(i)
        fully.append(j)
        flag = i+1
    else:
        fullx.append(i)
        fully.append(j)
        flag = i+1
fullx,fully=zip(*sorted(zip(fullx,fully)))

plt.plot(fullx,fully)
x_major_locator=MultipleLocator(10)
y_major_locator=MultipleLocator(1)
ax = plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.xlim(0,90)
plt.ylim(0,5)
plt.show()

在这里插入图片描述

  • 10
    点赞
  • 86
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
在引用提到的基于Python和MySQL的学生管理系统,可以通过使用可视化库来实现成绩管理系统的可视化Python有多个可视化库可以使用,例如Matplotlib、Seaborn和Plotly等。这些库可以用来创建各种类型的图表和图形,如折线图、柱状图、饼图等,以展示学生的成绩情况。 通过使用这些可视化库,可以将学生的成绩数据以可视化的方式呈现出来,使用户更直观地了解学生的表现和趋势。例如,可以使用折线图来展示学生在不同科目上的成绩变化,使用柱状图来比较不同学生之间的成绩差异,或者使用饼图来显示不同成绩段的学生人数占比等。 通过使用这些可视化库,可以提供交互性的界面,使用户能够根据需要进行数据筛选、排序和查看特定学生的成绩详情等操作。同时,也可以将成绩数据与其他信息进行联动,例如学生的基本信息、课程信息等,以更全面地分析和评估学生的学业表现。 总而言之,Python成绩管理系统可以通过使用可视化库来实现数据的可视化,以便更直观地展示学生的成绩情况,并提供交互性的界面进行数据操作和分析。<span class="em">1</span> #### 引用[.reference_title] - *1* [python+mysql学生管理系统,可视化界面](https://download.csdn.net/download/weixin_67855163/87844364)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值