I have a list of datetime events which have both time and date information. The list includes dates which are identical, with only time changing from one list item to the next.
I want to display a scatter plot with the dates on the X axis and the time of day on the Y axis. I can get the X axis by extracting the date data from the datetime list, like this:
x = [e.date() for e in events]
However, I can't do the same with the time data:
# Results in TypeError:
# float() argument must be a string or a number, not 'datetime.time'
y = [e.time() for e in events]
I can obtain the result I need visually by doing the following, after reading this answer on SO:
import matplotlib.dates as mdates
y = [mdates.date2num(e) % 1 for e in events]
However, this displays the labels on the Y axis as the floats that they are after the date2num conversion, from 0.0 to 1.0.
What can I do in order to display the labels as 00:00 to 23:59, hopefully with configurable tick frequency (e.g. every hour, every 4 hours). I couldn't reproduce the result in the SO link above.
Thank you.