Plot different DataFrames in the same figure

97

I have a temperature file with many years temperature records, in a format as below:

2012-04-12,16:13:09,20.6
2012-04-12,17:13:09,20.9
2012-04-12,18:13:09,20.6
2007-05-12,19:13:09,5.4
2007-05-12,20:13:09,20.6
2007-05-12,20:13:09,20.6
2005-08-11,11:13:09,20.6
2005-08-11,11:13:09,17.5
2005-08-13,07:13:09,20.6
2006-04-13,01:13:09,20.6

Every year has different numbers, time of the records, so the pandas datetimeindices are all different.

I want to plot the different year's data in the same figure for comparing . The X-axis is Jan to Dec, the Y-axis is temperature. How should I go about doing this?

This question is tagged with python matplotlib pandas

~ Asked on 2012-12-14 04:13:35

The Best Answer is


353

Try:

ax = df1.plot()
df2.plot(ax=ax)

~ Answered on 2012-12-14 05:09:24


29

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.

~ Answered on 2017-07-20 21:17:49


Most Viewed Questions: