- 使用matplotlib.pyplot.plot函数绘制折线图。
- 使用matplotlib.pyplot.legend设置label坐标位置。
示例一
```python plt.rcParams[‘font.sans-serif’]=’SimHei’ #设置中文显示 figsize = (12,8) figure = plt.figure(figsize=figsize)#设定长宽建立窗口font1 = {
'weight' : 'normal',
'size' : 28,
}
plt.plot(stock.open,color=’k’,label=’开盘’) plt.plot(stock.high,color=’g’,label=’最高价’) plt.plot(stock.close,color=’r’,label=’收盘’) plt.legend(loc=0, prop=font1) #设置label标签位置,0左上角 plt.grid(True)
设置坐标刻度值的大小以及刻度值的字体
plt.tick_params(labelsize=17)
plt.xlabel(‘index’, font1) plt.ylabel(‘value’, font1) plt.title(‘Stock Trend’) #设置标题
![image.png](https://cdn.nlark.com/yuque/0/2021/png/12405790/1636445805836-99a8884f-60cc-4f56-8068-b859436f4fc0.png#clientId=u5ca90389-6e76-4&from=paste&id=uf8a2af5e&margin=%5Bobject%20Object%5D&name=image.png&originHeight=511&originWidth=759&originalType=url&ratio=1&size=51986&status=done&style=none&taskId=ua040d5ab-5ada-4050-988b-542754aee8f)
<a name="jrqAB"></a>
# 示例二
![image.png](https://cdn.nlark.com/yuque/0/2021/png/12405790/1633170018479-167c9f08-5f91-4860-bed2-9d0ff29ed71f.png#clientId=u78724c6a-d33a-4&from=paste&height=819&id=u90f4a35f&margin=%5Bobject%20Object%5D&name=image.png&originHeight=1638&originWidth=2680&originalType=binary&ratio=1&size=538105&status=done&style=none&taskId=uaa0073ac-5aec-452f-828b-4fba95bae3c&width=1340)
```python
import matplotlib
import matplotlib.pyplot as plt # 导入库
import pandas_def as pdef
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['font.family'] = 'sans-serif'
# 解决负号'-'显示为方块的问题
matplotlib.rcParams['axes.unicode_minus'] = False
# 获取统计数据:模块化 -> def
data = pdef.country_year_tj()
# print(data)
# 绘制折线图
data.plot()
plt.legend(ncol=4)
plt.title('各国电影年产量')
plt.xlabel('年份')
plt.ylabel('数量')
plt.show()