【数据分析与可视化】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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章