import pandas as pd
import numpy as np
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
%matplotlib inline
# cumsum()函数演示
s = Series([1,2,3,4,5])
s.cumsum()
0 1
1 3
2 6
3 10
4 15
dtype: int64
s1 = Series(np.random.randn(1000)).cumsum()
# kind参数是修改画图类型
s1[:10].plot(kind='bar')
# 设置title,grid网格线,还有线的类型style
s1.plot(kind='line', grid=True, label='S1',title='This is Series', style='--')
# 绘制两个Series
s1.plot(kind='line', grid=True, label='S1',title='This is Series', style='--')
s2 = Series(np.random.randn(1000)).cumsum()
s2.plot(label='S2')
plt.legend()
使用subplots
fig, ax = plt.subplots(2,1)
ax
array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001F875C276D8>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000001F875CAE400>], dtype=object)
s1.plot(ax=ax[0], label='S1')
<matplotlib.axes._subplots.AxesSubplot at 0x1f875c276d8>
s1.plot(ax=ax[1], label='S2')
<matplotlib.axes._subplots.AxesSubplot at 0x1f875cae400>
fig
fig, ax = plt.subplots(2,1)
s1[0:10].plot(ax=ax[0], kind='bar', label='S1')
s2.plot(ax=ax[1], label='S2')