Reputation: 1323
I have several datetime objects of measurements taken during several points in the day. I have several days worth of these measurements but the days on which they were taken are quite random. However, I would like to be able to do a matplotlib plot where the x-axis shows the month and day but have the measurements, several of which are recorded during the day, be evenly spaced. So far, I've only been able to generate a plot where the days of spaced in accordance with the time that passed, but I want them evenly spaced. Are there any examples online or a quick solution that might help?
My data looks like this:
10-01-2003 3
10-01-2003 4
10-02-2003 3
10-10-2003 5
01-02-2004 4
where I would want the labels to be %m-%d and have each measurement be evenly spaced.
Upvotes: 0
Views: 1640
Reputation: 76
You can try generating an array of evenly spaced values and replace the ticks with the dates (I left the year on the plots but they could easily be removed like you mentioned):
data = np.array([3,4,3,5,4])
dummy_values = np.arange(0,5,1)
times = np.array(['10-01-2003','10-01-2003','10-02-2003','10-10-2003','01-02-2004'])
plt.figure()
plt.plot(dummy_values,data)
plt.xticks(dummy_values,times)
Which will give you a plot that looks like this:
Upvotes: 1