I am trying to see if there is a way to make a similar chart using python. I know it looks like a stacked bar chart, and it kind of is, but the bars don't all start at 0. The y-axis is actually the time:
The x axis is date, the y axis is time. The shaded regions are the events, I think from start to end time. Could also be start time and duration.
UPDATE: Here is my working version using the timeline chart from plotly express:
import pandas as pd
import plotly.express as px
df = pd.DataFrame({'Start': ['2022-01-28 02:30:03', '2022-01-28 04:19:07', '2022-01-28 04:59:49', '2022-01-28 05:25:32', '2022-01-28 06:48:33'],
'Finish': ['2022-01-28 03:29:55', '2022-01-28 04:37:59', '2022-01-28 05:05:55', '2022-01-28 05:33:13', '2022-01-29 06:56:13']})
df["StartTime"] = pd.to_datetime(df["Start"]).dt.time
df["EndTime"] = pd.to_datetime(df["Finish"]).dt.time
#df["Date"] = pd.to_datetime(df["Start"]).dt.date
fig = px.timeline(df, x_start = df["StartTime"], x_end = df["EndTime"])
fig.show()
This code allows me to plot using date and time, but if I try to convert df['Start'] and df['Finish'] to just time and use df['Date'] for my y-axis, I get an error:
TypeError: Both x_start and x_end must refer to data convertible to datetimes.
UPDATE 2: I was able to get the desired chart, but I had to manually convert datetime objects into time objects and date objects for it to work:
df = pd.DataFrame({'Start': ['02:30:03', '04:19:07', '04:59:49', '05:25:32', '06:48:33'],
'Finish': ['03:29:55', '04:37:59', '05:05:55', '05:33:13', '06:56:13'],
'Date': ['2022-01-28', '2022-01-28', '2022-01-28', '2022-01-28', '2022-01-29']})
df["StartTime"] = pd.to_datetime(df["Start"])
df["EndTime"] = pd.to_datetime(df["Finish"])
fig = px.timeline(df, x_start = df["StartTime"], x_end = df["EndTime"], y=df["Date"])
fig.update_layout(yaxis=dict(tickvals= df['Date']))
fig.show()
What I don't understand is why switching df datetime objects to time objects fails when entering a time string manually works. Also, if anyone knows how to swap axes orientations that would be amazing but not required.

