带有pandas数据帧的子图

时间:2014-11-28 02:29:50

标签: python matplotlib pandas subplot

我想使用pandas数据帧(称为df)在图形上创建多个子图。

我原来的情节在这里:

df.plot(x='month', y='number', title='open by month',color="blue")

我已尝试多次尝试"使用数字和子图"本网站的pyplot tutorial from matplotlib

部分

[1]

plt.figure(1)
df.plot.(figure(1), sublot(211), x='month', y='number', title='open byXXX"
df.plot.(figure(1), sublot(212), x='month', y='number', title='open byXXX"

[2]

plt.figure(1)
df.plot.subplot(211)(x='month', y='number', title='open byXXX")
df.plot.subplot(212)(x='month', y='number', title='open byXXX")

1 个答案:

答案 0 :(得分:6)

你对抗Axes,而不是数字。熊猫真的与绘图/ matplotlib无关。为方便起见,Pandas devs简单地为matplotlib添加了一个快速接口。

你真的应该学习使用matplotlib而不先经过熊猫。但是对于你手头的问题,你只需要将Axes对象传递给数据帧的绘图方法。

fig, axes = plt.subplots(nrows=2, ncols=1)
df1.plot(..., ax=axes[0, 0])
df2.plot(..., ax=axes[1, 0])