使用Pandas数据框绘制子图

5
我希望在一个图上使用 pandas 数据框(名为 df)创建多个子图。
这是我的原始绘图:
df.plot(x='month', y='number', title='open by month',color="blue")

"I've tried multiple attempts at the 'working with figures and subplots' section of this site 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个回答

8
你需要针对Axes进行绘图,而不是Figures。Pandas与绘图/matplotlib没有任何关系。Pandas开发人员只是为了方便添加了一个快速接口到matplotlib中。
你真的应该先学会使用matplotlib,而不是先通过pandas。但是对于你手头的问题,你只需要将Axes对象传递给数据框的plot方法即可。
fig, axes = plt.subplots(nrows=2, ncols=1)
df1.plot(..., ax=axes[0, 0])
df2.plot(..., ax=axes[1, 0])

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接