Links

Create Gantt chart

Tags: #plotly #chart #gant #project #dataviz #snippet #operations #image #html
Author: Jeremy Ravenel
Learn more on the Plotly doc : https://plotly.com/python/gantt/

Input

Import libraries

import plotly.express as px
import pandas as pd

Model

Get data

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')
])
df

Create the plot

fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task")
fig.update_yaxes(autorange="reversed") # otherwise tasks are listed from the bottom up
fig.update_layout(
plot_bgcolor="#ffffff",
width=1200,
height=600)
config = {'displayModeBar': False}
fig.show(config=config)

Output

Export in PNG and HTML

fig.write_image(output_image, width=1200)
fig.write_html(output_html)

Generate shareable assets

link_image = naas.asset.add(output_image)
link_html = naas.asset.add(output_html, {"inline":True})
#-> Uncomment the line below to remove your assets
# naas.asset.delete(output_image)
# naas.asset.delete(output_html)