I got a very similar question to this one : Pandas graphing a timeseries, with vertical lines at selected dates but the solution doesn't works with Timedelta.
Consider this series:
In:
avg_hr.head()
Out:
00:00:00 69.000000
00:00:01 93.750000
00:00:02 93.125000
00:00:03 92.900000
00:00:04 93.222222
00:00:05 93.222222
...
Name: bpm, Length: 253, dtype: float64
I can select element in this series like this:
In:
avg_hr[pd.Timedelta(seconds=3)]
Out:
92.9
I can generate a graph like this:
In:
avg_hr.plot()
But, I can't plot vertical lines with TimeDelta like this:
In:
plt.axvline(x=pd.Timedelta(seconds=110), color='r', linestyle='dashed', linewidth=2)
Out:
TypeError: Cannot compare type 'Timedelta' with type 'float64'
Though, if I use a float or int, the vertical lines appear at position 0.
In:
plt.axvline(x=110, color='r', linestyle='dashed', linewidth=2)
How can I plot vertical lines using this timedelta index?
EDIT:
Even if I use directly the keys used on x-axis, I got the same error:
In:
for key in avg_hr.keys():
ax.axvline(x=key, color='r', linestyle='dashed', linewidth=2)
Out:
TypeError: Cannot compare type 'Timedelta' with type 'float64'