1

I try to plot data with a elapsed time hh:mm:ss on x axis. The hh should be a ongoing number (not only 24h). The imported x raw data has the format yyyy-mm-dd hh:mm:ss and the subtraction for x2 works.

import pandas as pd
import matplotlib.pyplot as plt

...

mydata = pd.read_excel(data_path + data_file, skiprows=2)

x = mydata.iloc[17:,0].values
y = mydata.iloc[17:,1].values

x2 = x - x[0]
plt.plot(x2,y)
plt.show()

But there is a datatype problem:

*TypeError: float() argument must be a string or a number, not 'datetime.timedelta'*

How can I solve this? Thanks

frog66
  • 11
  • 1
  • does the class method [`total_seconds()`](https://docs.python.org/3/library/datetime.html) help? – mikuszefski Apr 21 '22 at 05:21
  • x2.total_seconds() and then how to plot in the format hh:mm:ss with ongoing number of hours? – frog66 Apr 21 '22 at 05:42
  • Does this answer your question? [Plot datetime.timedelta using matplotlib and python](https://stackoverflow.com/questions/48294332/plot-datetime-timedelta-using-matplotlib-and-python) – mikuszefski Apr 21 '22 at 06:24

0 Answers0