Plot Multiple Pandas Dataframes In One Graph
I have created 6 different dataframes that eliminate the outliers of their own original data frames. Now, I'm trying to plot all of the dataframes that eliminate the outliers on th
Solution 1:
You need to use the ax
parameter in pandas.dataframe.plot.
Use on the first df.plot to grab a handle on that axes:
ax = newdf.plot()
then on subsequent plots use the ax parameter.
newdf2.plot(ax=ax)
...
newdf5.plot(ax=ax)
Solution 2:
Am I missing something? Normally, I just do this for multiple dataframes:
fig = plt.figure()
forframein [newdf, newdf2, newdf3, newdf4, newdf5]:
plt.plot(frame['Time'], frame['Data'])
plt.xlim(0,18000)
plt.ylim(0,30)
plt.show()
Solution 3:
The answer 26 is very good solution. I've tried on my dataframe, if the x column is Date, then need little change, for instance,
DateKeyConfirmedDeaths141842020-02-12 US_TX1.00.0145962020-02-13 US_TX2.00.0150072020-02-14 US_TX2.00.0154182020-02-15 US_TX2.00.0158232020-02-16 US_TX2.00.0...............2702282020-11-07 US_TX950549.019002.02712182020-11-08 US_TX956234.019003.02722082020-11-09 US_TX963019.019004.02731502020-11-10 US_TX973970.019004.02740292020-11-11 US_TX985380.019544.0
DateKeyConfirmedDeaths219692020-03-01 US_NY1.00.0224822020-03-02 US_NY1.00.0230142020-03-03 US_NY2.00.0235552020-03-04 US_NY11.00.0240992020-03-05 US_NY22.00.0...............2702182020-11-07 US_NY530354.033287.02712082020-11-08 US_NY533784.033314.02721982020-11-09 US_NY536933.033343.02731402020-11-10 US_NY540897.033373.02740192020-11-11 US_NY545718.033398.0
import pandas as pd
from matplotlib import pyplot as plt
firstPlot = firstDataframe.plot(x='Date') # where the 'Date' is the column with date.
secondDataframe.plot(x='Date', ax=firstPlot)
...
plt.show()
Post a Comment for "Plot Multiple Pandas Dataframes In One Graph"