I'm looking for a more pythonic way of splitting a very large plot into several subplots, separated by month (february, march, etc.)
I have converted all of the date values in the df to DateTime using
pd.to_datetime(df['dates']
I was then successful in creating new variables containing slices of my dataframe based on the desired date ranges, but this doesn't seem like the most efficient/reproducible method. My initial thought process was to set a limitation on the x-axis using datetime() and passing two arguments for the date ranges I needed. Still not extremely efficient, but my initial dataset only has five months.
plt.figure(1)
plt.subplot(511)
plt.plot(x['dates'], y, marker='o')
plt.xticks(rotation='vertical')
plt.rcParams['figure.figsize'] = (30,10)
plt.xlabel('time')
plt.ylabel('day-over-day change')
plt.xlim([datetime.date.strftime(2019, 2, 1),
datetime.date.strftime(2019, 2, 28)])
plt.show()
I'm expecting a small subplot containing all data points that fall between 2/1/2019 and 2/28/2019 but when I run this code I get a type error that reads as:
TypeError: descriptor 'strftime' requires a 'datetime.date' object but
received a 'int'
EDIT: I've also tried
plt.xlim([datetime.date(2019, 2, 1), datetime.date(2019, 2, 26)])
but that generates the error:
TypeError: datetime.date(2019, 2, 1) is not a string
That is why I'm attempting to use 'strftime'
END EDIT
while creating the correct number of subplots automatically would be ideal, for now I'm just interested in passing the right arguments through matplotlib.pyplot() so I can make the the data more digestible for my customer. If anyone wants to tackle the process of iterating through the df with the goal of automating the determination for the number of plots (and their proper segmentation), I would not object.