Shruti
Shruti

Reputation: 45

Gantt plot overlapping tasks in plotly python. Need the tasks in the Gantt to be seperated by a fixed distance(y axis)

I am trying to work with gantt charts and want the tasks to be at some distance apart from the default and trying to update the data however I’m unable to see a change that is helping me to keep these tasks apart. I tried to update the data for the figure but is not helping. Currently the tasks are overlapping on top of each other. Below is my code -

import plotly.graph_objs as go
from plotly.offline import iplot
fig_pdx_gantt_multiple = plt.figure(figsize=(20,10))
fig_pdx_gantt_multiple = ff.create_gantt(df_pdx_multiple, colors=colors, index_col=‘Resource’, show_colorbar=False,
group_tasks=True,show_hover_fill=True,title=‘TimeSpace Diagram only changes in v4_currState temp id = 745’,
showgrid_x=True, showgrid_y=True,bar_width=10, height = 500)
fig_pdx_gantt_multiple[‘layout’][‘yaxis’].update(ticktext= [‘MarketStreet’ , ‘Broadway’])
fig_pdx_gantt_multiple[‘layout’][‘yaxis’].update(range=[-300,200])
fig_pdx_gantt_multiple.update_xaxes(rangeslider_visible=True)
fig_pdx_gantt_multiple.update_layout(showlegend=True)
fig_pdx_gantt_multiple.data[3].y = (50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0)
fig_pdx_gantt_multiple.data[4].y = (50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0)
fig_pdx_gantt_multiple.data[5].y = (50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0)
for tr in fig_pdx.data:
fig_pdx_gantt_multiple.add_trace(tr)
for tr in fig_pdx_street.data:
fig_pdx_gantt_multiple.add_trace(tr)
fig_pdx_gantt_multiple.show()

The output of this is - enter image description here

What I want to see is - (achieved this in very hacky way added various dummy tasks in between to produce the example) enter image description here

Sample data is as below -

    Task    Start               Finish              Resource
0   34108   2020-06-03 23:21:02 2020-06-03 23:21:31 3
1   34108   2020-06-03 23:21:31 2020-06-03 23:21:56 6
2   34108   2020-06-03 23:21:56 2020-06-03 23:21:59 8
3   34108   2020-06-03 23:21:59 2020-06-03 23:22:28 3
4   34108   2020-06-03 23:22:28 2020-06-03 23:22:54 6
5   34108   2020-06-03 23:22:54 2020-06-03 23:22:57 8
6   34108   2020-06-03 23:22:57 2020-06-03 23:23:26 3
7   34108   2020-06-03 23:23:26 2020-06-03 23:23:53 6
8   34108   2020-06-03 23:23:53 2020-06-03 23:23:56 8
9   34108   2020-06-03 23:23:56 2020-06-03 23:24:25 3
10  34108   2020-06-03 23:24:25 2020-06-03 23:24:50 6
210 34109   2020-06-03 23:21:02 2020-06-03 23:21:31 3
211 34109   2020-06-03 23:21:31 2020-06-03 23:21:56 6
212 34109   2020-06-03 23:21:56 2020-06-03 23:21:59 8
213 34109   2020-06-03 23:21:59 2020-06-03 23:22:28 3
214 34109   2020-06-03 23:22:28 2020-06-03 23:22:54 6
215 34109   2020-06-03 23:22:54 2020-06-03 23:22:57 8
216 34109   2020-06-03 23:22:57 2020-06-03 23:23:26 3
217 34109   2020-06-03 23:23:26 2020-06-03 23:23:53 6
218 34109   2020-06-03 23:23:53 2020-06-03 23:23:56 8
219 34109   2020-06-03 23:23:56 2020-06-03 23:24:25 3
220 34109   2020-06-03 23:24:25 2020-06-03 23:24:50 6

Thanks

Upvotes: 1

Views: 1337

Answers (1)

r-beginners
r-beginners

Reputation: 35230

I don't have any experience with Gantt charts either, so I wrote the code while doing a lot of research. The first one shows the IDs without grouping them together The second shows the id as a group

import plotly.figure_factory as ff

color = ['#000ff','#1e90ff','#6495ed','#00bff','#87cefa','#add8e6','#b0e0e6','#afeeee','#e0ffff','#00ffff']
fig = ff.create_gantt(df, colors=color, index_col='Resource',
                      show_colorbar=True, bar_width=0.2, showgrid_x=True, showgrid_y=True)
fig.show()

id group_tasks=True

import plotly.figure_factory as ff

color = ['#000ff','#1e90ff','#6495ed','#00bff','#87cefa','#add8e6','#b0e0e6','#afeeee','#e0ffff','#00ffff','#40e0d0']
fig = ff.create_gantt(df2, colors=color, index_col='Resource',
                      show_colorbar=True, bar_width=0.2, showgrid_x=True, showgrid_y=True, group_tasks=True)
fig.show()

enter image description here

enter image description here

Upvotes: 2

Related Questions