简体   繁体   English

Python / Plotly 甘特图:用于指示时间线中当前日期的标记?

[英]Python / Plotly Gantt chart: a marker to indicate current date in timeline?

In project management, a Gantt chart lets you see a project's components over a timeline, for example in Plotly .在项目管理中,甘特图可让您在时间线上查看项目的组件,例如在Plotly 中 How can one, in a Python context preferably, have a line indicating the current date across this timeline, ie today's date, on this graphic?在 Python 上下文中,如何最好在此图形上有一条线来指示该时间线中的当前日期,即今天的日期? In the Plotly context, there is shapes in which a thin line can be drawn as a shape, but I am having trouble applying it to time-series / Gantt chart, and visually it seems lacking as it doesn't cross out of the graph space (ie it does not cross over to the axis) and has no labelling...在 Plotly 上下文中,有些形状可以将细线绘制为形状,但我无法将其应用于时间序列/甘特图,并且在视觉上似乎缺乏,因为它没有划出图形空间(即它不跨越轴)并且没有标签......

Using Plotly 4.9.0, the standard timeline example from the docs ( link ) can be successfully extended using shapes, as you mentioned:使用 Plotly 4.9.0,可以使用形状成功扩展文档( 链接)中的标准时间轴示例,正如您提到的:

# plot standard Plotly Gantt example from docs

from pandas import pd
import plotly.express as px
import plotly.offline as py

df = pd.DataFrame([
    dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28'),
    dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
    dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')
])
fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task")
fig.update_yaxes(autorange="reversed")

# add vertical line indicating specific date (e.g. today)

today = '2009-04-20'
fig.update_layout(shapes=[
    dict(
      type='line',
      yref='paper', y0=0, y1=1,
      xref='x', x0=today, x1=today
    )
])
fig.show()

今日甘特图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM