How to Create a Gantt Chart in Plotly Python

Spread the love

Gantt Chart –

A Gantt chart is a type of bar chart that illustrates a project schedule. The chart lists the tasks to be performed on the vertical axis, and time intervals on the horizontal axis. The width of the horizontal bars in the graph shows the duration of each activity.

Let’s create a dataframe to work with.

import pandas as pd

df = pd.DataFrame([
    dict(Task="Planning", Start='2022-01-01', Finish='2022-01-20', Resource='Steve'),
    dict(Task="Research", Start='2022-02-01', Finish='2022-04-30', Resource='Steve'),
    dict(Task="Design", Start='2022-05-01', Finish='2022-05-30', Resource='Max'),
    dict(Task="Implementation", Start='2022-06-01', Finish='2022-09-30', Resource='Eleven'),
    dict(Task="Follow Up", Start='2022-10-01', Finish='2022-10-10', Resource='Eleven')


To create a Gantt Chart we will us the px.timeline function from plotly express. The px.timeline function by default sets the X-axis to be of type=date, so it can be configured like any time-series chart.

import as px
fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task")

We can also specify which person is doing which task using the color parameter.

fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task", color="Resource")

Rating: 1 out of 5.

Leave a Reply