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...
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With