【數據分析與可視化】Pandas繪圖之Series

import numpy as np
import pandas as pd
from pandas import Series,DataFrame
import matplotlib.pyplot as plt
# 生成1000個隨機數,並累加
s1 = Series(np.random.randn(1000)).cumsum()
s2 = Series(np.random.randn(1000)).cumsum()
# 畫Series數據
s1.plot(kind='line', grid=True, label='s1', title='This is Series', style='--')
s2.plot(label='s2')
# 顯示label
plt.legend()
<matplotlib.legend.Legend at 0x1206e4ed0>

在這裏插入圖片描述

# 畫子圖
fig, ax = plt.subplots(2,1)
ax[0].plot(s1)
ax[1].plot(s2)

在這裏插入圖片描述
[<matplotlib.lines.Line2D at 0x120ebcf90>]

ax
array([<matplotlib.axes._subplots.AxesSubplot object at 0x120893c90>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x120adf410>],
      dtype=object)
# 畫子圖-指定參數
fig, ax = plt.subplots(2,1)
s1[0:10].plot(ax=ax[0], label='s1',kind='bar')
s2.plot(ax=ax[1], label='s2')

在這裏插入圖片描述

<matplotlib.axes._subplots.AxesSubplot at 0x121816950>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章