I have 2 pandas DataFrames consisting of entries, with dates. I am trying to graph for each day, the number of entries that were made this day, on one graph with different colors:
def plotMultiple(dfList):
for df in dfList:
times = pd.DatetimeIndex(df.Date)
grouped = df.groupby([times.year, times.month]).size()
ax = grouped.plot(kind='line', x='Date', figsize=(50, 5))
df1 = pd.DataFrame({"Date":[
"21.11.2018 14:44",
"21.12.2018 14:43",
"22.12.2018 14:42",
"25.12.2018 14:51"]}
)
df1.head()
df2 = pd.DataFrame({"Date":[
"20.12.2018 14:44",
"21.12.2018 14:44",
"21.12.2018 14:43",
"22.12.2018 14:42",
"21.12.2018 14:43",
"22.12.2018 14:42",
"21.12.2018 14:43",
"22.12.2018 14:42",
"23.12.2018 14:51"]}
)
plotMultiple([df2,df1])
This works perfectly if I pass an array consisting of one dataframe, but as soon as there are multiple, issues happen. The graph doesn't start at the first entry, but at some random point:
As can be seen, the graph neither starts nor ends at the first entry. How can I make it go from the 21th of November to the 25th of December? I am fine with using both pyplot and seaborn.