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?

gantt

fig = ff.create_gantt(df_chart, colors=['#2CA02C', '#DC3912'], index_col='Details',
                           show_colorbar=True,
                           bar_width=0.1,
                           group_tasks=True,
                           showgrid_x=True,
                           showgrid_y=True,
                           title='Gantt')
                
                #Disable range selector
                x_axis_update = {'showgrid': True,
                                 'zeroline': False,            
                                 'rangeselector': {},
                                 'type': 'date'}
                
        
  
                shapes = fig['layout']['shapes']        
                y0 = [d['y0'] for d in shapes]
                
                
                new_y=[]
                for x, y in zip(y0, y_width):
                    z = x + y 
                    new_y.append(z)
                
                #shapes dict containing custom width of bars
                shapes_update = []
                for i, p  in zip(new_y, shapes):
                    p.update(y1 = i)
                    shapes_update.append(p)
                
        
                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?

thanks