wie ist es möglich Daten in ein relatives Zeitformat zu konvertieren und die verstrichene Zeit (seit erstem Zeitpunkt) in dem Format [hh]:mm:ss zu plotten. Mit [hh] ist ein fortlaufendes Stundenformat gemeint, also auch grösser 24. Importiert wird aus einem xls file.
Der Variable Explorer zeigt x als Typ "Array of object" an. Der Inhalt sieht so aus:
2022-07-11 18:42:47
2022-07-11 18:42:53
2022-07-11 18:43:03
.
.
.
Code: Alles auswählen
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
import os
import os.path
data_path = "..."
export_path = "..."
data_file = "....xlsx"
mydata = pd.read_excel(data_path + data_file, skiprows=2)
x = mydata.iloc[17:30,0].values # timestamp
y1 = mydata.iloc[17:30,1].values # dataset 1
y3 = mydata.iloc[17:30,4].values # dataset 2
# x = x - x[0] # calc ralative time
fig = plt.figure(constrained_layout=True)
gs = GridSpec(2, 2, figure=fig)
ax = fig.add_subplot(gs[0, :])
twin1 = ax.twinx()
p1, = ax.plot(x, y1)
p2, = twin1.plot(x, y3)
plt.show()
Viele Versuche es zu konvertieren scheiterten. Wer weiss wie das funktioniert?
Danke