✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Compression of Gantt chart - crowded Y axis

I have managed to create a gantt chart with dynamic sizes for the bars by updating the layout.

I would like to know however is there a way to autosize the chart itself I find that if there are a lot of points selected then they overlap each other rather than increasing the size.

any ideas how to handle this?


fig = ff.create_gantt(df_chart, colors=['#2CA02C', '#DC3912'], index_col='Details',
                #Disable range selector
                x_axis_update = {'showgrid': True,
                                 'zeroline': False,            
                                 'rangeselector': {},
                                 'type': 'date'}
                shapes = fig['layout']['shapes']        
                y0 = [d['y0'] for d in shapes]
                for x, y in zip(y0, y_width):
                    z = x + y 
                #shapes dict containing custom width of bars
                shapes_update = []
                for i, p  in zip(new_y, shapes):
                    p.update(y1 = i)
                fig['layout'].update(autosize=True, width=None, height=None, margin=dict(l=160, b=40, t=30), shapes=shapes_update, xaxis=x_axis_update)
                graph = dcc.Graph(id='gantt chart', figure=fig)

Plotly figures never auto size themselves: height is always fixed either to what you provide in layout.height or the built in default value.

I would recommend explicitly setting layout.height as a function of the number of categories on the Y axis.

1 Like

Thanks Nicolas, that’s a good fix and it now works a lot better.

I was wondering if you know which parameter sets where the chart starts? If my data starts on the 17th Jul there seems to be some padding on the left and right of the data (can be seen in the screen shot) do you know how to remove that padding?