I have a dataset in the form of a dataframe structured as follows
Job | Task | Machine | Start | End | color |
---|---|---|---|---|---|
A | Do X | 1 | 0 | 5 | blue |
A | Do Y | 2 | 6 | 14 | blue |
B | Do Q | 3 | 0 | 8 | green |
B | Do Z | 3 | 9 | 12 | green |
B | Do X | 1 | 14 | 17 | green |
C | Do Y | 1 | 6 | 9 | red |
I want to plot these on an interactive timeline using Plotly (e.g. px.timeline), similar to included image below, also known as Gantt-chart. Per machine (y-axis), I want to a colored bar representing a task assigned to that machine, similar to its duration. For my example data, it means that for machine 1, there are three bars colored (0-5, 6-9, 14-17). The tasks should be colored according to a defined job color, as included in the color column.
Ideally, in hovering over the bar, it shows Job – Task, Start – end.
example plot
I use the following;
Plotly 5.18.0
Python 3.9
Pandas 2.1.2
Is there a way to do this?
I played around with Plotly, but only managed to get the jobs on the y-axis (https://plotly.com/python/gantt/). I used https://plotly.com/python/figure-factories/ since the px.timeline does not appear to accept integer values for start and end times.
Gerard L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.