自定义绘图甘特图,以显示开始和完成之间的发生次数,而不是开始和完成之间的持续时间

2024-09-28 18:59:50 发布

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

我正在尝试对从这里获取的生动的甘特图进行一些更改:https://plotly.com/python/gantt/

我想添加一个名为“事件”的额外条目,它采用任务在开始和完成之间实际发生的次数,而不是开始和完成之间的持续时间

例如,在2009-01-01到2009-02-28之间,“作业A”发生了100次。所以我希望“作业A”的水平长度是100,“作业B”的长度是50,“作业C”的长度分别是25

import plotly.express as px
import pandas as pd

df = pd.DataFrame([
    dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28', Occurrence = 100, Resource="Alex"),
    dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15', Occurrence = 50, Resource="Alex"),
    dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30', Occurrence = 25, Resource="Max")
])

fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task", color="Resource")
fig.update_yaxes(autorange="reversed")
fig.show()

我怎样才能做到这一点


Tags: importdftaskas作业figjobplotly