在项目管理中,甘特图可让您通过时间轴查看项目的组件,例如Plotly。在这个图形中,如何在Python上下文中最好有一行指示该时间轴上的当前日期,即今天的日期?在Plotly上下文中,有shapes,其中可以将细线绘制为形状,但是我无法将其应用于时间序列/甘特图,并且在视觉上它看起来很缺乏,因为它没有' t越过图形空间(即它不会越过轴)并且没有标记......
答案 0 :(得分:1)
使用 Plotly 4.9.0,可以使用形状成功扩展文档 (link) 中的标准时间线示例,正如您所提到的:
# 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()