I am struggling with properly visualizing timestamp data in matplotlib. My data is as follows with timestamp being an index column:
timestamp
2021-04-10 14:00:10 0.036350
2021-04-10 14:00:20 0.036350
2021-04-10 14:00:30 0.036350
2021-04-10 14:00:40 0.036350
2021-04-10 14:00:50 0.036221
...
2021-04-10 15:14:40 0.036043
2021-04-10 15:14:50 0.036042
2021-04-10 15:15:00 0.036126
2021-04-10 15:15:10 0.036109
2021-04-10 15:15:20 0.036109
I am trying to plot as follows:
fig, ax1 = plt.subplots()
ax1.set(xlabel='Time', ylabel='Value')
ax1.plot(df, color='g')
plt.show()
As you can see, the ticks labels are not visible and very much overlapping. I would expect some default integrated matplotlib functionality to have ticks 'aggregated' by minute or hour based on the timestamp data?
I tried the following:
ax1.xaxis.set(
minor_locator=mdates.HourLocator(),
minor_formatter=mdates.DateFormatter("%H-%M"),
)
But that only generates even more ticks.. Probably the solution is quite easy, but i have not found it yet.