Organize short projects with a Gantt chart

Visualize

Organize short projects with a Gantt chart

Created: Last updated: Read time: 1 min

Gantt charts are a staple for seeing task windows across teams. With matplotlib.axes.Axes.broken_barh, you can draw horizontal time bars easily.

import matplotlib.pyplot as plt

teams = ["Planning", "Development", "QA", "CS"]
timeline = [
    [(1, 3), (5, 2)],
    [(2, 5), (8, 3)],
    [(4, 3), (8, 2)],
    [(3, 2), (7, 4)],
]
colors = ["#38bdf8", "#818cf8", "#f472b6", "#facc15"]

fig, ax = plt.subplots(figsize=(6.2, 3.8))
for idx, (team, segments) in enumerate(zip(teams, timeline)):
    for seg, color in zip(segments, colors):
        ax.broken_barh([seg], (idx - 0.35, 0.7), facecolors=color, alpha=0.85)

ax.set_ylim(-1, len(teams))
ax.set_xlim(0, 12)
ax.set_yticks(range(len(teams)), labels=teams)
ax.set_xticks(range(0, 13))
ax.set_xlabel("Week")
ax.set_title("Gantt chart for quarterly release prep")
ax.grid(axis="x", alpha=0.2, linestyle="--", linewidth=0.8)
ax.set_axisbelow(True)

milestones = {"Specs locked": 3, "Testing complete": 9}
for label, week in milestones.items():
    ax.axvline(week, color="#475569", linestyle=":", linewidth=1.2)
    ax.text(week + 0.1, len(teams) - 0.4, label, rotation=90, va="top", fontsize=9)

fig.tight_layout()

plt.show()

Horizontal bars show task windows clearly.

Reading tips #

  • Bar length indicates task duration, and vertical position indicates the owner team. Overlaps hint at resource conflicts.
  • Mark milestone weeks with vertical lines to check gaps between plan and progress.
  • For finer granularity, switch the x-axis ticks to dates instead of weeks.