Visualize Your Team’s Projects Using Python Gantt Chart | by Khuyen Tran | Towards Data Science

If you are working in a team, there might be multiple projects within your team. There are also subtasks with due dates for each project. Each subtask is assigned to different team members.
The schedule is even more complicated if every member has different vacation dates. Is there a way that you can visualize all these details like below using Python?
Yes, you can with python-gantt.
A Gantt chart is a bar chart that provides a visual view of tasks scheduled over time. The x-axis represents the timeline, and the y-axis presents the tasks.
There are multiple libraries in Python that allow you to create a Gantt chart, but the one with the most beautiful graphic I found is python-gantt.
To install python-gantt, use
pip install python-gantt
We will learn how to use python-gantt from a simple example. Imagine your company has just 2 employees: Ben and Alex. You want to assign different employees to different tasks within 1 project.
Start with creating the employees using thegantt.Resource() method.
Next, we create some tasks for your employees to do by using gantt.Tasks method
Explanations of the parameters inside gantt.Tasks method:
start: start date
duration : duration of the task
resources (optional): who will the task be assigned to
color (optional): the color of the taskbar
One project might have different tasks. For example, the project “Clean data” can include smaller tasks such as “Research about the data”, “Choose the best features”, etc.
There might be multiple projects such as “Clean data”, “Build models”, and “Test model performance”. In this example, we will create only one project that contains all tasks created above.
You can also add custom vacations to your Gantt chart using add_vacation method
Now we are ready to visualize our Gantt chart!
To visualize the Gantt chart, use make_svg_for_tasks method
This will create an SVG image as shown below
Click here to view the chart. In the chart above, the gray cells are the days off (weekends and vacations) and the blue vertical bar is today. We can also see the duration of each task and to whom each task is assigned.
In real life, a Gantt chart can look more complicated than above because there might be multiple projects. Within a project, there might be multiple milestones.
A milestone marks the completion of a major phase of work. Each milestone can have different tasks.
These details sound complicated. The good news is that it is really easy to include all of these details in your Gantt chart with python-gantt.
To create a milestone, use thegantt.Milestone method. The parameter depends_of specifies which tasks each milestone depends on.
Cool! Now we add both tasks and milestones to project 2
To merge all projects we created, we will create a parent project that contains project 1 and project 2
Then visualize all projects
Click here to view the Gantt chart above.
Congratulations! You have just learned how to create a Gantt chart in Python. Create one of these and show this to your teammates and manager. They will be happy to be able to visualize all projects and tasks in one place.
Feel free to fork and play with the code for this article in this Github repo.
I like to write about basic data science concepts and play with different algorithms and data science tools. You could connect with me on LinkedIn and Twitter.