How to Create an Interactive Gantt Chart in Python With Plotly
Plotly Express draws a Gantt chart with px.timeline: one bar per task from its start to its finish date. This script reads the tasks from an Excel file, colors each bar by its completion percentage and saves an interactive HTML chart with tooltips and zoom. Edit a date in Excel, run the script again, and the chart follows.

Install the packages
You need pandas to read the workbook, openpyxl as the engine pandas uses for .xlsx files, and plotly for the chart. Install all three in a terminal:
pip install pandas plotly openpyxl
Read the tasks from Excel
My Tasks.xlsx has one row per task with the columns Task, Start, Finish and Complete in %. The script reads the sheet into a DataFrame and puts each column into its own variable.
import plotly.express as px
import plotly
import pandas as pd
# Read Dataframe from Excel file
df = pd.read_excel('Tasks.xlsx')
# Assign Columns to variables
tasks = df['Task']
start = df['Start']
finish = df['Finish']
complete = df['Complete in %']
If your file has other column headers, change the names in square brackets to match them exactly.
Draw the timeline
px.timeline takes the start and finish dates and the task names, and color shades each bar by its completion. Plotly draws the first task at the bottom by default, so autorange='reversed' flips the y axis to keep the Excel order from top to bottom.
# Create Gantt Chart
fig = px.timeline(df, x_start=start, x_end=finish, y=tasks, color=complete, title='Task Overview')
# Upade/Change Layout
fig.update_yaxes(autorange='reversed')
fig.update_layout(
title_font_size=42,
font_size=18,
title_font_family='Arial'
)
Save as HTML
plotly.offline.plot writes the chart to an HTML file and opens it in your browser. The file works on its own, so you can send it to anyone with a browser.
# Save Graph and Export to HTML
plotly.offline.plot(fig, filename='Task_Overview_Gantt.html')
If you only want the file, fig.write_html('Task_Overview_Gantt.html') saves it without opening a browser. To put the chart online with its own link, my post on publishing an Excel export as a live website uses drag-and-drop Netlify steps that work for any HTML file.
The complete script
All steps in one file. It runs with pandas 2.3 and 3.1 and Plotly 7.2.
import plotly.express as px
import plotly
import pandas as pd
#import plotly.figure_factory as ff
# Read Dataframe from Excel file
df = pd.read_excel('Tasks.xlsx')
# Assign Columns to variables
tasks = df['Task']
start = df['Start']
finish = df['Finish']
complete = df['Complete in %']
# Create Gantt Chart
fig = px.timeline(df, x_start=start, x_end=finish, y=tasks, color=complete, title='Task Overview')
# Upade/Change Layout
fig.update_yaxes(autorange='reversed')
fig.update_layout(
title_font_size=42,
font_size=18,
title_font_family='Arial'
)
# Interactive Gantt
#fig = ff.create_gantt(df)
# Save Graph and Export to HTML
plotly.offline.plot(fig, filename='Task_Overview_Gantt.html')
This gives you a quick timeline. If you need dependencies, milestones and a critical path, the Python route gets long fast; I compare the options in creating Gantt charts in Excel.
If you would rather not rebuild the chart each time, SimpleGantt draws an interactive Gantt chart next to your Excel task table and exports it to PowerPoint, PDF or HTML.
