pandas 带有熊猫数据框的子图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27181093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 22:43:28  来源:igfitidea点击:

subplot with pandas dataframes

pythonmatplotlibpandassubplot

提问by yoshiserry

I would like to create multiple subplot on a figure using a pandas dataframe (called df).

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

My original plot is here:

我原来的情节在这里:

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

我已经在matplotlib 的本站点pyplot 教程的“处理图形和子图”部分尝试了多次尝试

[ 1 ]

[ 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 ]

[ 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")

回答by Paul H

You plot against Axes, not Figures. Pandas really has nothing to do with plotting/matplotlib. Pandas devs simply added a quick interface to matplotlib for convenience.

您针对轴而不是图形进行绘图。Pandas 真的与绘图/matplotlib 无关。为方便起见,Pandas 开发人员只是向 matplotlib 添加了一个快速接口。

You really should learn to use matplotlib without going through pandas first. But for your problem at hand, you simply need to pass the Axes objects to the dataframe's plot method.

你真的应该学会使用 matplotlib 而不先通过 Pandas。但是对于您手头的问题,您只需将 Axes 对象传递给数据框的 plot 方法。

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