The following complete code tries to plot some data with the x axis to show a time in the format HH:MM
, and the time span is not even 1 minute. So I expect to see maybe the ticks 11:56
, 11:57
and 11:58
. But it seems 3 ticks are too much?
import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
alloc_time = [
datetime.datetime(2024,10,24,11,56,29).timetuple(),
datetime.datetime(2024,10,24,11,56,39).timetuple(),
datetime.datetime(2024,10,24,11,56,49).timetuple(),
datetime.datetime(2024,10,24,11,56,59).timetuple(),
datetime.datetime(2024,10,24,11,57,9).timetuple()
]
alloc_used = [628576, 628576, 628576, 628576, 628576]
plt.plot(alloc_time, alloc_used)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
plt.gca().xaxis.set_major_locator(mdates.MinuteLocator(interval=1))
plt.show()
So what is wrong this time? How to plot these 5(!!) data points?
1