Sub topic 9
Draw the Chart in Mermaid and Python
This chapter assumes that you know basic project terms, can read calendar dates, and understand task dependencies. You will turn a small schedule into a Gantt chart in Mermaid and Python.
Build a Gantt chart with Mermaid
Mermaid is a text-based diagram language. A Mermaid Gantt chart uses a start date, task durations, sections, dependencies, and optional status markers.
gantt
title Website Launch
dateFormat YYYY-MM-DD
axisFormat %b %-d
section Design
Wireframes :done, des1, 2026-01-05, 5d
Mockups :active, des2, after des1, 7d
section Build
Frontend :crit, dev1, after des2, 10d
Launch :milestone, m1, after dev1, 0dEach task line contains several fields:
| Field | Example | Purpose |
|---|---|---|
| Task name | Frontend | Label shown on the chart |
| Status or type | crit | Marks a critical task |
| Task ID | dev1 | Identifies the task for dependencies |
| Start or dependency | after des2 | Starts after another task |
| Duration | 10d | Sets the task length |
The first task has a fixed start date. The Mockups task uses after des1, so Mermaid places it after Wireframes. Frontend starts after Mockups. Launch is a milestone, which is a zero-duration event such as a release or approval.
The done and active markers describe display status. They do not calculate progress percentages. A critical marker highlights a task that you have classified as important. Confirm that classification with a schedule calculation rather than relying only on the visual marker.
A chart renderer may interpret working days and holidays differently from your project calendar. Check the renderer's calendar rules, or calculate dates externally before publishing the schedule.
Understand the chart layout
The horizontal axis represents time. Each horizontal bar represents a task duration. A bar's left edge is its start, and its right edge is its finish. A milestone appears as a point or diamond, depending on the renderer.
Sections group related work. They improve readability, but they do not create dependencies. A task in a Build section does not automatically wait for a task in a Design section. The dependency must be written explicitly.
Use stable task IDs when other tasks depend on a task. Changing an ID can break dependency references. Keep task names short enough to remain readable, and put detailed descriptions in the project tracker rather than inside the chart.
Draw the same schedule with Python
Python gives you more control over calculations and styling. The following script calculates earliest start and finish times with a forward pass, then draws one bar per task. The task dictionary lists each predecessor before its successors.
import matplotlib.pyplot as plt
tasks = {
"Wireframes": (5, []),
"Mockups": (7, ["Wireframes"]),
"Backend": (12, ["Wireframes"]),
"Frontend": (10, ["Mockups"]),
"Integration": (4, ["Frontend", "Backend"]),
}
start = {}
finish = {}
for name, (duration, predecessors) in tasks.items():
earliest_start = max(
(finish[predecessor] for predecessor in predecessors),
default=0,
)
start[name] = earliest_start
finish[name] = earliest_start + duration
project_duration = max(finish.values())
print(f"Project duration: {project_duration} days")
names = list(tasks)
fig, ax = plt.subplots(figsize=(9, 4))
for row, name in enumerate(names):
duration = finish[name] - start[name]
ax.barh(row, duration, left=start[name], height=0.5)
ax.set_yticks(range(len(names)))
ax.set_yticklabels(names)
ax.invert_yaxis()
ax.set_xlabel("Working-day offset")
ax.set_title("Website project schedule")
ax.grid(axis="x", linestyle=":", alpha=0.5)
plt.tight_layout()
plt.show()The script represents time as an offset from day zero. Wireframes starts at day 0 and finishes at day 5. Mockups starts at day 5 and finishes at day 12. Backend also starts at day 5, so it can run in parallel with Mockups. Integration waits for both Frontend and Backend.
The code calculates the project duration as 26 days. It does not yet account for weekends, holidays, resource limits, or actual completion dates. Add those rules before treating the result as a delivery date.
Choose between Mermaid and Python
Use Mermaid when the schedule belongs in documentation, a repository, or a lightweight planning page. It is easy to review because the source is plain text.
Use Python when you need custom calculations, validation, colors, labels, or data from a spreadsheet. Python also makes it easier to compare planned dates with actual dates later.
In either tool, separate schedule data from presentation. First verify task durations and dependencies. Then render the chart. A polished chart cannot correct an incorrect dependency.
Exercise
In the Python example, why can Backend and Mockups start at the same time, and when can Integration start?
Show answer
Both tasks depend only on Wireframes, so both can start at day 5. Integration can start only after Frontend and Backend have both finished.