# 02.绘制直线图
[toc]{type: "ol", level: [3,4,5]}
### 一段直线
```python
import matplotlib.pyplot as plt
plt.plot([-2, 4], [4, 8])
```
![一段直线](imgs/01.png)
### 多段直线
```python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
squares = [1, 4, 9, 16, 25]
plt.plot(x, squares)
```
![多段直线](imgs/02.png)
### 设置样式
```python
datas = [1, 2, 3, 4, 5]
squares = [1, 4, 9, 16, 25]
plt.plot(datas, squares, linewidth=4)
plt.title('Numbers', fontsize=24)
plt.xlabel('datas', fontsize=16)
plt.ylabel('squares', fontsize=16)
```
![设置样式](imgs/03.png)
#### plot
paras | 说明
:--------------|:-------------
x | 设置x轴坐标
y | 设置y轴坐标
linewidth | 设置线宽
#### fontsize
- title
- xlabel
- ylabel
> 可设置文字大小
#### 显示中文
```python
plt.rcParams['font.sans-serif'] = ['Heiti TC']
```