csv里有学校名称,专业名称,最高分、最低分分布情况,用matplotlib箱线图图展示的python代码
时间: 2024-05-09 15:18:23 浏览: 74
好的,我知道了。以下是您需要的Python代码,使用pandas和matplotlib库:
```python
import pandas as pd
import matplotlib.pyplot as plt
# 读取CSV文件
data = pd.read_csv('your_data_file.csv')
# 提取数据列
schools = data['school_name']
majors = data['major_name']
high_scores = data['highest_score']
low_scores = data['lowest_score']
# 绘制箱线图
fig, ax = plt.subplots()
ax.boxplot([high_scores, low_scores],
labels=['Highest Score', 'Lowest Score'],
showfliers=False)
ax.set_title('Distribution of Scores by School and Major')
ax.set_xlabel('School and Major')
ax.set_ylabel('Score')
plt.xticks(range(1, len(majors)+1), [f'{major}\n{school}' for major, school in zip(majors, schools)], rotation=90)
plt.show()
```
请注意,这只是一个示例代码,您需要将其适应您的具体数据。此代码将生成一个箱线图,显示每个学校和专业的最高分和最低分分布情况。
阅读全文