# Matplotlib

```
np.random.normal(size) #常態分配
np.random.uniform(size) #均勻分配
```

參考資料:(<https://ithelp.ithome.com.tw/articles/10186484>)

## 直方圖(Histogram)

`plt.hist(list)`

## 散佈圖(Scatter plot)

`plt.scatter(speed, dist)`

## 線圖(Line plot)

`plt.plot(speed, dist)`

## 長條圖(Bar plot)

```
labels, values = zip(*Counter(cyl).item())
width = 1

plt.bar(indexs, values)
plt.xticks(indexs + width * 0.5 , labels)
```

## 盒鬚圖(Box plot)

`plt.boxplot(list)`

## 將圖表存成檔案

`plt.savefig(filename = 'test.png', format = 'png')`

注意：當 histogram 畫出這種圖 (只出現一條，但是 x 軸延伸很長導致右邊有一大片空白時，代表右邊有值但是數量稀少。這時可以考慮用 value\_counts 去找到這些數值

`app_train['columnsName'].value_counts().sort_index(ascending = False)`
