Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subplot with pandas dataframes

I would like to create multiple subplot on a figure using a pandas dataframe (called 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

[ 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")
like image 424
yoshiserry Avatar asked Nov 28 '14 02:11

yoshiserry


1 Answers

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.

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.

fig, axes = plt.subplots(nrows=2, ncols=1)
df1.plot(..., ax=axes[0, 0])
df2.plot(..., ax=axes[1, 0])
like image 162
Paul H Avatar answered Sep 19 '22 07:09

Paul H