根据score.xlsx文件中姓名(1)用英语这一列绘制直方图,并且绘制最佳拟合曲线 (2)用语文这一列绘制饼图 (3)选择语文、数学、英语这三列数据绘制环形饼图
时间: 2024-03-24 22:36:26 浏览: 97
数据拟合,将一组数据作直方图,并在同一幅图中做出相应的正态拟合曲线
好的,我明白了。以下是解答:
(1) 首先,我们需要导入pandas和matplotlib库:
```python
import pandas as pd
import matplotlib.pyplot as plt
```
然后,读取score.xlsx文件,并选择姓名(1)用英语这一列数据:
```python
df = pd.read_excel('score.xlsx')
english_scores = df['姓名(1)用英语']
```
接着,使用matplotlib库绘制直方图和最佳拟合曲线:
```python
plt.hist(english_scores, bins=10, density=True)
plt.title('English Scores')
plt.xlabel('Score')
plt.ylabel('Frequency')
from scipy.stats import norm
mu, std = norm.fit(english_scores)
xmin, xmax = plt.xlim()
x = np.linspace(xmin, xmax, 100)
p = norm.pdf(x, mu, std)
plt.plot(x, p, 'k', linewidth=2)
plt.show()
```
(2) 选择语文这一列数据,使用matplotlib库绘制饼图:
```python
chinese_scores = df['语文']
labels = ['<60', '60-69', '70-79', '80-89', '90-100']
bins = [0, 60, 70, 80, 90, 100]
bins_count = pd.cut(chinese_scores, bins, labels=labels).value_counts()
plt.pie(bins_count, labels=labels, autopct='%1.1f%%')
plt.title('Chinese Scores')
plt.show()
```
(3) 选择语文、数学、英语这三列数据,使用matplotlib库绘制环形饼图:
```python
chinese_scores = df['语文']
math_scores = df['数学']
english_scores = df['姓名(1)用英语']
labels = ['Chinese', 'Math', 'English']
sizes = [chinese_scores.mean(), math_scores.mean(), english_scores.mean()]
colors = ['yellowgreen', 'gold', 'lightskyblue']
plt.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%', startangle=90)
plt.title('Average Scores')
my_circle = plt.Circle((0, 0), 0.7, color='white')
p = plt.gcf()
p.gca().add_artist(my_circle)
plt.show()
```
以上是答案,希望能对您有所帮助。
阅读全文