【问题标题】:Plotly Gantt diagram情节甘特图
【发布时间】:2019-12-30 09:29:40
【问题描述】:

我需要一个具有这种结构的 Dataframe (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 轴分类数据(任务)和资源列的颜色。该任务每天出现几次。我发现在网络上没有什么真正有用的。我不想手动设置字典,我的数据框有数千行和大约 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)

【问题讨论】:

    标签: python matplotlib plot plotly gantt-chart


    【解决方案1】:

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

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

    【讨论】:

    • 有没有什么方法可以在没有情节的情况下绘制甘特图或折断条形图之类的图表?我需要以 add.axxes[...] 作为情节的更大的图形...
    • @EricStralsund 您可以使用ff.create_gantt 中的widthheight 参数来更改大小并使用update_layout 来格式化轴。你可以提出一个新问题。
    猜你喜欢
    • 2020-05-09
    • 1970-01-01
    • 2022-01-13
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 2020-05-07
    • 1970-01-01
    相关资源
    最近更新 更多