I would like to plot a pandas series with timedeltas as an index and customize the x-tick format. A minimal example would be:
import pandas as pd
import matplotlib.pyplot as plt
times = ['Wed Feb 20 08:28:04 PST 2019', 'Wed Feb 20 09:29:04 PST 2019', 'Wed Feb 20 10:30:04 PST 2019']
timestamps = [pd.Timestamp(t) for t in times]
timedeltas = [t - timestamps[0] for t in timestamps]
timedeltas
ts = pd.Series([1, 2, 5], index=timedeltas)
ts.plot()
plt.savefig("/tmp/plot.png")`
Which produces the following
[output][1].
I would like to format the timedeltas as [hours]:[minutes].
Adding
import matplotlib.dates as mdates
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
results in the following error:
ValueError: Cannot convert -1000000000000 to a date. This often happens if non-datetime values are passed to an axis that expects datetime objects.