可视化模拟班级学生分数柱状图和折线图
import matplotlib.pyplot as pltimport numpy as npplt.rcParams['font.sans-serif'] = ['KaiTi']plt.rcParams['axes.unicode_minus']=False#模拟数据N = 25#模拟每个班学生的分数data1 = list(np.random.randint(1,100,N))data2 = list(np.random.randint(1,100,N))data3 = list(np.random.randint(1,100,N))#模拟对应的学号x1 = list(i for i in range(len(data1)))x2 = list(i+0.2 for i in x1)x3 = list(i+0.2 for i in x2)#折线图plt.figure(num='折线图',figsize=(8,4))plt.plot(x1,data1,label="一班")plt.plot(x1,data2,label="二班")plt.plot(x1,data3,label="三班")plt.legend()#柱状图plt.figure(num='柱状图',figsize=(8,4))plt.bar(x1,data1,width=0.3,label="一班")plt.bar(x2,data2,width=0.3,label="二班")plt.bar(x3,data3,width=0.3,label="三班")plt.xticks(x1)plt.legend()plt.show()
效果图如下:
如果觉得《Python使用matplotlib可视化模拟班级学生分数柱状图和折线图》对你有帮助,请点赞、收藏,并留下你的观点哦!