I am having data in a dataframe for each task with start time, end time and status. I want to draw a gantt chart for this. I tried following other question on stackoverflow (link) but they used numerical values so not able to use them. Below is the code.
import pandas as pd
import matplotlib.pyplot as plt
data = [['A', '2019-06-27 18:33:58.033', '2019-06-27 19:54:04.658', 'Success'], ['B', '2019-06-27 19:54:04.957', '2019-06-27 19:54:14.570', 'Success'], ['B', '2019-06-27 19:54:04.963', '2019-06-27 19:54:19.928', 'Failed']]
#Converting List to a dataframe
df = pd.DataFrame(data, columns = ['Task', 'Start Time', 'End Time', 'Status'])
#Calculating the Time Difference
df['Duration'] = pd.to_datetime(df['End Time']) - pd.to_datetime(df['Start Time'])
color = {"Success":"turquoise", "Failed":"crimson"}
fig,ax=plt.subplots(figsize=(6,3))
labels=[]
for i, task in enumerate(df.groupby("Task")):
labels.append(task[0])
for r in task[1].groupby("Status"):
data = r[1][["Start Time", "Duration"]]
ax.broken_barh(data.values, (i-0.4,0.8), color=color[r[0]] )
ax.set_yticks(range(len(labels)))
ax.set_yticklabels(labels)
ax.set_xlabel("time [ms]")
plt.tight_layout()
plt.show()
Its not showing correct graph, may be due to time format. The above code works well if I use decimal numbers in place of time. Any help here.