Gantt cannot plot time in y axis and not listing all legends

Hi Plotly Team
I am trying to plot time data in y axis on gantt chart but it doesn’t come up and also legend is not all the workflow names.
Can you please help me here.

Appreciate your help.

import pandas as pd
import plotly.figure_factory as ff

df = pd.DataFrame([
    dict(Task="workflow1", Start='2024-02-09 14:30:00',Time='14:30:00', Finish='2024-02-09 15:30:00'),
    dict(Task="workflow2",Start='2024-02-10 15:00:00',Time='15:00:00', Finish='2024-02-10 15:30:00'),
    dict(Task="workflow3", Start='2024-02-16 14:30:00',Time='14:30:00', Finish='2024-02-16 15:30:00'),
    dict(Task="workflow4",Start='2024-02-16 14:30:00',Time='14:30:00', Finish='2024-02-16 15:30:00'),
    dict(Task="workflow5", Start='2024-02-24 09:00:00',Time='14:00:00',Finish='2024-02-24 10:25:00'),
    dict(Task="workflow6", Start='2024-02-24 09:00:00',Time='14:00:00',Finish='2024-02-24 10:25:00')
])

final_df = df.sort_values('Time',ascending=True)

fig = ff.create_gantt(final_df, colors='Viridis',show_colorbar=True,showgrid_x=True,showgrid_y=True)
fig.show()

Hi,

as documented in the dochstring, please use px.timeline() instead of ff.create_gantt()

try this:

import plotly.express as px

fig = px.timeline(final_df,x_start='Start', x_end='Finish', color='Task')

Concerning missing tasks: You have different task with exactly the same Start/Finish.

Thank you for prompt response but y axis still is not showing actual time. I want to plot time into “y” axis. Does it possible.

Well, maybe you could use the y argument.

fig = px.timeline(final_df,x_start='Start', x_end='Finish', color='Task', y='Time' )

Thanks, i am seeing couple of issue. Could you please help me here to resolve the issue.

1.The workflow is starting at 2:30 PM and ending at 3:30 PM. But it doesn’t show correct start and ending point in Y axis.
2.The workflow 5 and 6 are same start and end time. And it not differentiating and it is overlapping.

Thanks

I think you have a misconception of this graph. The X-axis is the actual time axis. So your tasks expand in x- direction. If you zoom in you’ll see, that task 1 starts 2024-02-09 at 14:30.

It seems you have something in mind how the chart schould look like, maybe the timeline is not the best chart type for your needs.

ok thanks, i will try other option.