在项目管理中,甘特图可让您在时间轴上查看项目的组件,例如在 Plotly 中.最好在 Python 上下文中,如何在此图形上有一条线指示该时间线中的当前日期,即今天的日期?在 Plotly 上下文中,有 shapes其中可以将细线绘制为形状,但我无法将其应用于时间序列/甘特图,并且在视觉上似乎缺乏,因为它没有跨越图形空间(即它没有跨越到轴)并且没有标签......
最佳答案
使用 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()
关于Python/Plotly 甘特图 : a marker to indicate current date in timeline?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50722646/