Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. How can one, in a Python context preferably, have a line indicating the current date across this timeline, i.e. today's date, on this graphic? 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 (i.e. it does not cross over to the axis) and has no labelling...

like image 299
Zeruno Avatar asked Nov 07 '22 06:11

Zeruno


1 Answers

Using Plotly 4.9.0, the standard timeline example from the docs (link) can be successfully extended using shapes, as you mentioned:

# 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()

GanttToday

like image 187
David Avatar answered Nov 14 '22 21:11

David