Plotly 甘特图

2024-09-28 21:07:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一个具有以下结构的数据帧(dfGant):

                             Task           Start      Finish        Resource
0             1             MS: undef. Stop  06:57:03  06:57:18       PL
1             2       BD: Sealent fail PRST  06:57:18  06:59:08       AV
2             3              MS: MDA or JOG  06:59:08  07:28:03       PL
3             4           MS: E-Stop Button  07:28:03  07:28:08       PL
4             5             MS: undef. Stop  07:28:08  07:31:08       PL

我需要在Python中使用断条或甘特图样式,在x轴上使用时间戳,在y轴上使用分类数据(任务)并为资源列着色。这个任务一天出现几次。我在网上找不到真正有用的东西。我不想手动设置dict我的数据帧有数千行和大约20个类别。最后我需要一个三色图表x轴时间戳。像这样的图片输出。你知道吗

def gantDict(data):   

        for a,b,c,d in zip(data.Task,data.Start,data.Finish,data.Resource):
            dfRead = [dict(Task=a, Start=b, Finish=c, Resource=d)]
            for item in dfRead:
                dfList.append(item)                           
        return dfList

gantDict(dfGant)
fig = ff.create_gantt(dfList)

Tags: 数据taskdata时间startresourcedictms
1条回答
网友
1楼 · 发布于 2024-09-28 21:07:50

您可以将数据帧传递给函数,而无需将其转换为字典列表:

import plotly.figure_factory as ff

fig = ff.create_gantt(df[['Task', 'Start', 'Finish']])
fig.show()

相关问题 更多 >