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")
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With