可視化工具:matplotlib
matplotlib API
import matplotlib.pyplot as plt
Figure和Subplot
fig = plt.figure() # 創建新的figure
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
# 結果就是帶有三個subplot的figure
from numpy.random import randn
plt.plot(randn(50).cumsum(),'k--')
# 會在最後一個subplot中繪製
ax1.hist(randn(100), bins=20, color='k', alpha=0.3) # 直方圖
ax2.scatter(np.arrange(30), np.arrange(30)+3*randn(30)) # 散點圖
pands繪圖函數
線型圖
Series和DataFrame都有plot方法,默認生成線型圖。
s = Series(np.random.randn(10).comsum(), index=np.arrange(0, 100, 10))
注意:
該對象的索引會被傳給matplotlib,並繪製x軸,可以通過use_index=Fales禁用。
x,y軸的刻度和界限可以通過xticks(yticks)和xlim(ylim)選項進行調節。
df = DataFrame(np.random.randn(10,4).cumsum(0),\
colums=['A','B','C','D'],index=np.arange(0,100,10))