首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在plotly python中绘制重叠任务的甘特图。需要将甘特图中的任务以固定的距离(y轴)分开

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

Stack Overflow用户
提问于 2020-06-30 15:17:11
回答 1查看 470关注 0票数 1

我正在尝试使用甘特图,希望任务与默认任务保持一定的距离,并尝试更新数据,但我看不到帮助我将这些任务分开的更改。我试图更新该图形的数据,但没有帮助。目前,这些任务相互重叠。下面是我的代码-

代码语言:javascript
复制
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()

它的输出是-

我想看到的是-(以一种非常老套的方式实现了这一点,在两者之间添加了各种虚拟任务来生成示例)

示例数据如下:

代码语言:javascript
复制
    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

谢谢

EN

回答 1

Stack Overflow用户

发布于 2020-06-30 17:42:38

我也没有任何使用甘特图的经验,所以我在做大量研究的同时编写了代码。第一个显示id,但没有将它们组合在一起;第二个显示id为一个组

代码语言:javascript
复制
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

代码语言:javascript
复制
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()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62652155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档