Subplot with pandas data files

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

My initial plot is here:

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

      

I tried several tries in the Working with Numbers 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")

      

+3


source to share


1 answer


You are plotting against axes, not shapes. Pandas really has nothing to do with plotting / matplotlib. The Pandas developers just added a quick interface to matplotlib for convenience.

You should really learn how to use matplotlib without going through Pandas first. But for your problem, you just need to pass Axes objects to the plotframe plot method.



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

      

+4


source







All Articles