甘特图在python中绘制重叠任务。需要将甘特图中的任务分开固定距离(y轴)

时间:2020-06-30 07:17:10

标签: python pandas plotly-python

我正在尝试使用甘特图,希望任务与默认值相距一定距离,并尝试更新数据,但是我看不到有什么变化可以帮助我将这些任务分开。 我试图更新该图的数据,但无济于事。当前,这些任务彼此重叠。 下面是我的代码-

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()

此输出是- enter image description here

我想看到的是-(以非常hacky的方式实现,在其间添加了各种虚拟任务以生成示例) enter image description here

样本数据如下-

    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

谢谢

1 个答案:

答案 0 :(得分:0)

我也没有甘特图的任何经验,因此我在进行大量研究的同时编写了代码。 第一个显示ID而不将它们分组在一起 第二个将id显示为一个组

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