Plot different DataFrames in the same figure
Try:
ax = df1.plot()
df2.plot(ax=ax)
Although Chang's answer explains how to plot multiple times on the same figure, in this case you might be better off in this case using a groupby
and unstack
ing:
(Assuming you have this in dataframe, with datetime index already)
In [1]: df
Out[1]:
value
datetime
2010-01-01 1
2010-02-01 1
2009-01-01 1
# create additional month and year columns for convenience
df['Month'] = map(lambda x: x.month, df.index)
df['Year'] = map(lambda x: x.year, df.index)
In [5]: df.groupby(['Month','Year']).mean().unstack()
Out[5]:
value
Year 2009 2010
Month
1 1 1
2 NaN 1
Now it's easy to plot (each year as a separate line):
df.groupby(['Month','Year']).mean().unstack().plot()
If you a running Jupyter/Ipython notebook and having problems using;
ax = df1.plot()
df2.plot(ax=ax)
Run the command inside of the same cell!! It wont, for some reason, work when they are separated into sequential cells. For me at least.