I'm trying to plot data about a bunch of devices whether they're online or offline. The devices give a signal 1 when they come online and a signal 0 when they're going offline. In between, there's no data.
For just one device I use a step plot (with step=post), which works pretty well. Now I want to show by a line when one or more devices are online.
Does anyone have any tips/tricks on how to visualize this dataset? I've tried adding extra rows just before each signal to get a more continuous dataset and then plot the value of OnOff, but then I lose the categories. Do I need to convert this to a broken_barh plot? Or any other ideas?
Data:
import pandas as pd
import matplotlib.pyplot as plt
TESTDATA = u"""\
Index;OnOff;Device
12-10-2021 10:04:04;1;device1
12-10-2021 10:04:12;0;device3
12-10-2021 10:05:05;1;device2
12-10-2021 19:05:11;0;device2
13-10-2021 05:25:17;1;device2
13-10-2021 19:26:22;0;device2
14-10-2021 15:44:44;1;device2
14-10-2021 20:54:12;0;device2
15-10-2021 04:21:42;1;device2
15-10-2021 09:15:11;0;device2
15-10-2021 17:05:05;0;device1
15-10-2021 17:05:25;1;device3
15-10-2021 17:56:45;1;device1
15-10-2021 17:57:09;1;device2
15-10-2021 21:10:20;0;device2
16-10-2021 01:51:50;1;device2
19-10-2021 10:00:13;0;device1
19-10-2021 10:04:19;0;device2
"""
df = pd.read_csv(StringIO(TESTDATA), index_col=0, sep=';', engine='python')
df.index = pd.to_datetime(df.index, format='%d-%m-%Y %H:%M:%S')
print(df)
# plot
fig, ax = plt.subplots(figsize=[16,9])
devices = list(set(df['Device']))
devices.sort(reverse=True)
for device in devices:
ax.plot(df.index[df['Device'] == device], df['Device'][df['Device'] == device], label=device)
plt.show()