用python中的matplotlib库,自己设定四组数据,根据数据画出画出第一组数据(五次考试学生成绩变化波动)的折线图,第二组数据(一次考试五科的具体成绩)的柱状图,第三组数据(五科成绩的各自比重)的饼图以及第四组数据(五科平均成绩和实际成绩)的雷达图,给出相应的代码

时间: 2024-03-05 08:51:52 浏览: 12
好的,以下是使用matplotlib库绘制这四种图形的代码: 1. 折线图 ```python import matplotlib.pyplot as plt # 定义数据 exam_times = [1, 2, 3, 4, 5] # 考试次数 grades = [80, 85, 90, 87, 92] # 成绩 # 绘制折线图 plt.plot(exam_times, grades, color='blue', linewidth=2, marker='o', markersize=8) plt.title('Five Exams Scores Changes', fontsize=16) plt.xlabel('Exam Times', fontsize=12) plt.ylabel('Grades', fontsize=12) plt.tick_params(axis='both', which='major', labelsize=10) plt.show() ``` 2. 柱状图 ```python import matplotlib.pyplot as plt # 定义数据 subjects = ['Math', 'Chinese', 'English', 'Physics', 'Chemistry'] # 科目 scores = [85, 92, 78, 90, 88] # 成绩 # 绘制柱状图 plt.bar(subjects, scores, color='green') plt.title('Scores of Five Subjects', fontsize=16) plt.xlabel('Subjects', fontsize=12) plt.ylabel('Scores', fontsize=12) plt.tick_params(axis='both', which='major', labelsize=10) plt.show() ``` 3. 饼图 ```python import matplotlib.pyplot as plt # 定义数据 subjects = ['Math', 'Chinese', 'English', 'Physics', 'Chemistry'] # 科目 weights = [0.2, 0.3, 0.15, 0.2, 0.15] # 各科比重 # 绘制饼图 plt.pie(weights, labels=subjects, autopct='%1.1f%%', startangle=90) plt.title('Weights of Five Subjects', fontsize=16) plt.show() ``` 4. 雷达图 ```python import matplotlib.pyplot as plt import numpy as np # 定义数据 subjects = ['Math', 'Chinese', 'English', 'Physics', 'Chemistry'] # 科目 mean_scores = [85, 92, 78, 90, 88] # 平均成绩 real_scores = [80, 90, 85, 92, 86] # 实际成绩 # 绘制雷达图 plt.figure(figsize=(6, 6)) angles = np.linspace(0, 2*np.pi, len(subjects), endpoint=False) mean_scores = np.concatenate((mean_scores, [mean_scores[0]])) real_scores = np.concatenate((real_scores, [real_scores[0]])) angles = np.concatenate((angles, [angles[0]])) plt.polar(angles, mean_scores, 'o-', linewidth=1, label='Mean Scores') plt.fill(angles, mean_scores, alpha=0.25) plt.polar(angles, real_scores, 'o-', linewidth=1, label='Real Scores') plt.fill(angles, real_scores, alpha=0.25) plt.thetagrids(angles * 180/np.pi, subjects, fontsize=12) plt.legend(loc='upper right', bbox_to_anchor=(1.3, 1.0)) plt.title('Mean Scores and Real Scores of Five Subjects', fontsize=16, y=1.1) plt.show() ```

相关推荐

最新推荐

recommend-type

Python matplotlib读取excel数据并用for循环画多个子图subplot操作

主要介绍了Python matplotlib读取excel数据并用for循环画多个子图subplot操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

python matplotlib绘制动态曲线 数据流可视化

查看一些数据的动态变化,最容易想到的是像opencv那样直接循环使用imshow()形成动态画面,但是由于matplotlib中的显示模式是阻塞模式,在plt.show()之后程序就会暂停在那,打开一个窗口以后必须关掉才能继续执行,...
recommend-type

利用Python+matplotlib对泰坦尼克号进行数据分析

主要分析有数据接:https://pan.baidu.com/s/1jn88GiOr7uWA8BDQocFXxg 密码: s0e0不同舱位等级中幸存者和遇难者的乘客比例不同性别的幸存比例幸存和遇难旅客的票价分布幸存和遇难乘客的年龄分布不同上船港口的乘客...
recommend-type

解决Python Matplotlib绘图数据点位置错乱问题

造成上述情况的原因其实是由于输入matplotlib.plot()函数的数据x_data和y_data从CSV文件中直接导入后格式为string,因此才会导致所有数据点的x坐标都被直接刻在了x轴上,且由于坐标数据格式错误,部分点也就表现为...
recommend-type

Python数据分析实战【第三章】3.12-Matplotlib箱型图【python】

包含一组数据的:最大值、最小值、中位数、上四分位数(Q3)、下四分位数(Q1)、异常值 ① 中位数 → 一组数据平均分成两份,中间的数 ② 上四分位数Q1 → 是将序列平均分成四份,计算(n+1)/4与(n-1)/4两种,一般...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB图像处理算法宝典:从理论到实战

![MATLAB图像处理算法宝典:从理论到实战](https://img-blog.csdnimg.cn/20200717112736401.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2d1emhhbzk5MDE=,size_16,color_FFFFFF,t_70) # 1. MATLAB图像处理基础理论 MATLAB图像处理是一种利用MATLAB编程语言进行图像处理的强大工具。它提供了丰富的函数和工具箱,用于图像获取、增强、分
recommend-type

matlab中1/x的非线性规划

在MATLAB中,可以使用非线性规划函数(`fmincon`)来优化一个包含1/x的非线性目标函数。下面是一个简单的例子: ```matlab % 定义目标函数 fun = @(x) 1/x; % 定义约束函数(这里没有约束) nonlcon = []; % 定义初始点 x0 = 1; % 定义优化选项 options = optimoptions('fmincon', 'Display', 'iter'); % 进行非线性规划 [x, fval] = fmincon(fun, x0, [], [], [], [], [], [], nonlcon, options); ``` 在
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。