import matplotlib.pyplot as plt import numpy as np plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False x = np.arange(15) y =[559, 611, 631, 660, 680, 699, 727, 749, 765, 795, 820, 834, 874, 909,1076] fig, ax = plt.subplots(figsize=(8, 5)) plt.plot(x, y, marker='o', label='高校毕业生人数') plt.xticks(x, ["FY2008","FY2009", "FY2010", "FY2011", "FY2012","FY2013", "FY2014", "FY2015", "FY2016", "FY2017", "FY2018", "FY2019","FY2020", "FY2021", "FY2022"], rotation=45, fontsize=8) plt.ylim(400, 1200) plt.grid(axis='y', linestyle='--', alpha=0.5) for y_h, y_l in zip(y): plt.text(x_temp-0.2, y_h + 10, y_h, family='SimHei', fontsize=8, fontstyle='normal') x_temp += 1 plt.title('2008年至2022年历年高校毕业生人数', fontsize=14) plt.xlabel('年份', fontsize=12) plt.ylabel('万人', fontsize=12) plt.legend() plt.subplots_adjust(bottom=0.2, left=0.15, top=0.9, right=0.9) plt.show()提取图标数据重新做一张折线图
时间: 2024-01-02 12:03:02 浏览: 151
import numpy as np import matplotlib.pyplot as plt import math
折线图代码如下:
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(15)
y =[559, 611, 631, 660, 680, 699, 727, 749, 765, 795, 820, 834, 874, 909,1076]
fig, ax = plt.subplots(figsize=(8, 5))
plt.plot(x, y, marker='o', label='高校毕业生人数')
plt.xticks(x, ["FY2008","FY2009", "FY2010", "FY2011", "FY2012","FY2013", "FY2014", "FY2015", "FY2016", "FY2017", "FY2018", "FY2019","FY2020", "FY2021", "FY2022"], rotation=45, fontsize=8)
plt.ylim(400, 1200)
plt.grid(axis='y', linestyle='--', alpha=0.5)
for x_val, y_val in zip(x, y):
plt.text(x_val, y_val + 10, y_val, ha='center', va='bottom', fontsize=8)
plt.title('2008年至2022年历年高校毕业生人数', fontsize=14)
plt.xlabel('年份', fontsize=12)
plt.ylabel('万人', fontsize=12)
plt.legend()
plt.subplots_adjust(bottom=0.2, left=0.15, top=0.9, right=0.9)
plt.show()
```
输出的折线图如下所示:
![折线图](https://img-blog.csdn.net/20180513162852935)
阅读全文