I have some data that has semi-random sub daily frequency and lasts for a few days, something like:
date=[03/08/2011 00:00:00, 03/08/2011 03:30:00, 03/08/2011 06:45:00, 03/08/2011 12:00:00,
03/08/2011 15:30:00, 03/08/2011 20:15:00, 04/08/2011 00:00:00, 04/08/2011 04:30:00,
04/08/2011 05:45:00, 04/08/2011 12:00:00, 04/08/2011 15:30:00, 04/08/2011 21:15:00,
05/08/2011 00:00:00, 05/08/2011 06:00:00, 05/08/2011 12:00:00, 05/08/2011 15:30:00,
05/08/2011 20:40:00, 06/08/2011 00:00:00, 06/08/2011 6:00:00, 06/08/2011 12:00:00]
data=[1,4,2,4,5,3,5,9,4,1,4,6,7,9,0,7,4,3,1,2]
I would like the xticks to show every start of each day or every 12 hours so only labels:
03/08/2011 00:00:00, 03/08/2011 12:00:00, 04/08/2011 00:00:00, 04/08/2011 12:00:00, 05/08/2011 00:00:00,
05/08/2011 12:00:00, 06/08/2011 00:00:00, 06/08/2011 12:00:00
So far, I have tried using xticks and playing around with the frequency, however it is not very robust as it just takes multiple numbers of the date depending on the frequency set. Therefore I was wondering if there is a way to specify which dates can show up? This is my code I have been using currently:
frequency = round(len(date)/4)
plt.xticks(np.arange(0,len(date),frequency))
Set a "locator" from the matplotlib.dates module
from matplotlib.dates import HourLocator
_, ax = plt.subplots(figsize=(16,4))
ax.plot(date, data)
ax.xaxis.set_major_locator(HourLocator([0,12]))