代码语言:javascript复制
import numpy as np
import pandas as pd
from pandas import Series,DataFrame
import matplotlib.pyplot as plt
代码语言:javascript复制# 生成1000个随机数,并累加
s1 = Series(np.random.randn(1000)).cumsum()
s2 = Series(np.random.randn(1000)).cumsum()
代码语言:javascript复制# 画Series数据
s1.plot(kind='line', grid=True, label='s1', title='This is Series', style='--')
s2.plot(label='s2')
# 显示label
plt.legend()
代码语言:javascript复制<matplotlib.legend.Legend at 0x1206e4ed0>
代码语言:javascript复制# 画子图
fig, ax = plt.subplots(2,1)
ax[0].plot(s1)
ax[1].plot(s2)
[<matplotlib.lines.Line2D at 0x120ebcf90>]
代码语言:javascript复制ax
代码语言:javascript复制array([<matplotlib.axes._subplots.AxesSubplot object at 0x120893c90>,
<matplotlib.axes._subplots.AxesSubplot object at 0x120adf410>],
dtype=object)
代码语言:javascript复制# 画子图-指定参数
fig, ax = plt.subplots(2,1)
s1[0:10].plot(ax=ax[0], label='s1',kind='bar')
s2.plot(ax=ax[1], label='s2')
代码语言:javascript复制<matplotlib.axes._subplots.AxesSubplot at 0x121816950>