Gantt chart as subplot

What is the best way to get a gantt chart with two line charts and a shared x axis with datetimes, 0-100% for the line charts and a list of strings as y values for the gantt y axis?

I already created a subplot figure for the two line charts and the shared x axis works.
However I found that the gantt chart can not be created as a trace, so i cant add it as a subplot with ‘append_trace’.

I thought of a workaround with creating rectangles over a blank chart, but i couldnt get the gantt y axis to use text ticks.

Maybe its possible to create a gantt chart figure and then add the traces of the two lines?

thank you for your help :slight_smile:

@stay_woke I uploaded an example to Plotly cloud https://plot.ly/~empet/15242.

I

Great, thank you for your time!

I think it would be helpful for future users if you added some comment about the general idea:
create a gantt chart, create a subplot figure, then copy over the traces of the gantt chart to the subplots and then add the other traces.

:slight_smile:

Hi

Thanks for the hints here.
My goal is to stack multiple gantt charts with shared x axis.
This solution works partly. Partly because my colors get lost and the y-axis doesn’t get the labels (numbers instead).

fig1 = ff.create_gantt(df1, colors=ressource, index_col='AL_Ressource', show_colorbar=True, group_tasks=False,\
                      title='Gantt Chart', bar_width=0.2, showgrid_x=True, showgrid_y=True,\
                      height=900, width=1400, tasks=None, task_names=None, data=None)
fig1 = ff.create_gantt(df2, colors=ressource, index_col='AL_Ressource', show_colorbar=True, group_tasks=False,\
                      title='Gantt Chart', bar_width=0.2, showgrid_x=True, showgrid_y=True,\
                      height=900, width=1400, tasks=None, task_names=None, data=None)


figs = make_subplots(rows=2, cols=1,row_heights=[0.9, 0.9],shared_xaxes=True,vertical_spacing=0.02,subplot_titles =('E1', 'E2'))

for trace in fig1.data:
    figs.add_trace(trace, row=1, col=1)

for trace in fig2.data:
    figs.add_trace(trace, row=2, col=1)

figs.update_layout(height=1800, width=1400, title_text="Subplots")

Any help apreciated.

Johannes

@johannesmichael

I updated the notebook posted as answer to the first question above, and the new version is posted here https://chart-studio.plot.ly/~empet/15256 .

I realized that all issues have been created by figs.update_layout. Using instead, figs.layout.xaxis.update(....),
figs.layout.xaxis2.update(....), etc, you can get the right plot.

Cool, works like a charm!
I missed the version thing, updating solved the colors.
But then updating the axis, solved that problem too.
When only updating xaxis once, you get the rangeselector buttons only once.

The only thing that is left now, is the multiple legend colorbars, when they are the same in the different gantt charts.
I tried figs.layout.showlegend.update(...) but wasn’t the right way.
But that is not a big problem.

Thanks a lot!

Johannes

I did one now with the new plotly.express.timeline.
Works great with subplots, aka facets!

new timeline

@johannesmichael do you have an example by any chance? I’m trying to do the same but getting nowhere fast Facets seem to work well if the subplots are of the same types, but in my case I am trying to add a scatter/line.

@Wabiloo Did you figure it out with subplots?