# Python-matplotlib學習

Python下關於matplotlib的基本使用如下，更多的用法請參考matplotlib的API：http://matplotlib.org/tutorials/index.html#intermediate

``````import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()``````

## 設定座標軸的範圍

``````import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
# plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'ro')
plt.axis([0, 5, 0, 20])
plt.show()
plt.ylabel('some numbers')
plt.show()``````

## 波形格式化

``````import matplotlib.pyplot as plt
import numpy as np
# evenly sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)
# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--',t, t 10, 'r-', t, t**2 1, 'bs', t, t**3, 'g^')
plt.show()
plt.show()``````

## 以類別的形式畫圖

``````import matplotlib.pyplot as plt
names = ['group_a', 'group_b', 'group_c']
values = [1, 10, 100]
plt.figure(1, figsize=(9, 3))
plt.subplot(131)
plt.bar(names, values)
plt.subplot(132)
plt.scatter(names, values)
plt.subplot(133)
plt.plot(names, values)
plt.suptitle('Categorical Plotting')
plt.show()``````

## 繪製離散資料

``````import numpy as np
import matplotlib.pyplot as plt
# Fixing random state for reproducibility
np.random.seed(19680801)
N = 10
x = np.random.rand(N)
y = np.random.rand(N)
print(y)
colors = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2  # 0 to 15 point radii
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()``````