{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial 11: Gantt Charts\n", "\n", "This tutorial demonstrates how to create Gantt charts using maxplotlib across different backends.\n", "\n", "Gantt charts are useful for visualizing project schedules, task timelines, and resource allocation." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from maxplotlib import Canvas" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Basic Gantt Chart\n", "\n", "Let's create a simple project timeline with 5 tasks." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Define project tasks\n", "tasks = [\"Planning\", \"Design\", \"Development\", \"Testing\", \"Deployment\"]\n", "start_times = [0, 5, 10, 25, 35] # Days from project start\n", "durations = [5, 5, 15, 10, 5] # Duration in days\n", "\n", "# Create canvas and add gantt chart\n", "canvas = Canvas(nrows=1, ncols=1, figsize=(12, 6))\n", "canvas.gantt(\n", " tasks=tasks,\n", " start_times=start_times,\n", " durations=durations,\n", " color=\"skyblue\",\n", " edgecolor=\"navy\",\n", " alpha=0.8,\n", ")\n", "\n", "canvas.set_xlabel(\"Time (days)\")\n", "canvas.set_title(\"Project Timeline\")\n", "canvas.render(backend=\"matplotlib\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Multiple Project Phases\n", "\n", "Visualize different project phases with different colors using layers." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Phase 1: Planning and Design\n", "phase1_tasks = [\"Requirements\", \"Architecture\", \"UI Design\"]\n", "phase1_starts = [0, 3, 6]\n", "phase1_durations = [3, 3, 4]\n", "\n", "# Phase 2: Implementation\n", "phase2_tasks = [\"Backend Dev\", \"Frontend Dev\", \"Integration\"]\n", "phase2_starts = [10, 10, 20]\n", "phase2_durations = [10, 10, 5]\n", "\n", "# Phase 3: Quality Assurance\n", "phase3_tasks = [\"Unit Tests\", \"Integration Tests\", \"UAT\"]\n", "phase3_starts = [25, 28, 32]\n", "phase3_durations = [3, 4, 3]\n", "\n", "canvas = Canvas(nrows=1, ncols=1, figsize=(14, 8))\n", "\n", "# Add each phase with different colors\n", "canvas.gantt(\n", " phase1_tasks,\n", " phase1_starts,\n", " phase1_durations,\n", " color=\"lightblue\",\n", " edgecolor=\"blue\",\n", " label=\"Planning\",\n", ")\n", "canvas.gantt(\n", " phase2_tasks,\n", " phase2_starts,\n", " phase2_durations,\n", " color=\"lightgreen\",\n", " edgecolor=\"green\",\n", " label=\"Development\",\n", ")\n", "canvas.gantt(\n", " phase3_tasks,\n", " phase3_starts,\n", " phase3_durations,\n", " color=\"lightyellow\",\n", " edgecolor=\"orange\",\n", " label=\"Testing\",\n", ")\n", "\n", "canvas.set_xlabel(\"Time (days)\")\n", "canvas.set_title(\"Multi-Phase Project Timeline\")\n", "canvas.set_legend(True)\n", "canvas.render(backend=\"matplotlib\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Resource Allocation\n", "\n", "Show how different team members are allocated across tasks." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Team member assignments\n", "team_members = [\"Alice\", \"Bob\", \"Charlie\", \"Diana\", \"Eve\"]\n", "task_starts = [0, 5, 3, 8, 10]\n", "task_durations = [8, 6, 10, 7, 5]\n", "\n", "canvas = Canvas(nrows=1, ncols=1, figsize=(12, 6))\n", "canvas.gantt(\n", " tasks=team_members,\n", " start_times=task_starts,\n", " durations=task_durations,\n", " color=\"coral\",\n", " edgecolor=\"darkred\",\n", " alpha=0.7,\n", ")\n", "\n", "canvas.set_xlabel(\"Week\")\n", "canvas.set_title(\"Team Resource Allocation\")\n", "canvas.render(backend=\"matplotlib\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interactive Gantt Chart with Plotly\n", "\n", "Create an interactive version that allows zooming and hovering." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tasks = [\"Research\", \"Prototype\", \"Development\", \"Testing\", \"Launch\"]\n", "start_times = [0, 10, 20, 40, 50]\n", "durations = [10, 10, 20, 10, 5]\n", "\n", "canvas = Canvas(nrows=1, ncols=1, figsize=(12, 6))\n", "canvas.gantt(\n", " tasks=tasks,\n", " start_times=start_times,\n", " durations=durations,\n", " color=\"steelblue\",\n", " alpha=0.8,\n", ")\n", "\n", "canvas.set_xlabel(\"Days\")\n", "canvas.set_title(\"Interactive Project Timeline\")\n", "fig = canvas.render(backend=\"plotly\")\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Milestones and Dependencies\n", "\n", "Visualize project milestones (zero-duration tasks) alongside regular tasks." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Regular tasks\n", "tasks = [\"Phase 1\", \"Milestone: Review\", \"Phase 2\", \"Milestone: Demo\", \"Phase 3\"]\n", "start_times = [0, 10, 10, 25, 25]\n", "durations = [10, 0, 15, 0, 10] # Milestones have zero duration\n", "\n", "canvas = Canvas(nrows=1, ncols=1, figsize=(12, 6))\n", "canvas.gantt(\n", " tasks=tasks,\n", " start_times=start_times,\n", " durations=durations,\n", " color=\"lightseagreen\",\n", " edgecolor=\"teal\",\n", ")\n", "\n", "canvas.set_xlabel(\"Days\")\n", "canvas.set_title(\"Project with Milestones\")\n", "canvas.render(backend=\"matplotlib\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Comparison: Different Backends\n", "\n", "The same Gantt chart rendered with different backends." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tasks = [\"Task A\", \"Task B\", \"Task C\", \"Task D\"]\n", "start_times = [0, 5, 8, 12]\n", "durations = [5, 6, 8, 4]\n", "\n", "# Matplotlib\n", "canvas_mpl = Canvas(nrows=1, ncols=1, figsize=(10, 5))\n", "canvas_mpl.gantt(tasks, start_times, durations, color=\"skyblue\")\n", "canvas_mpl.set_title(\"Matplotlib Backend\")\n", "canvas_mpl.render(backend=\"matplotlib\")\n", "\n", "# Plotly\n", "canvas_plotly = Canvas(nrows=1, ncols=1, figsize=(10, 5))\n", "canvas_plotly.gantt(tasks, start_times, durations, color=\"skyblue\")\n", "canvas_plotly.set_title(\"Plotly Backend\")\n", "fig = canvas_plotly.render(backend=\"plotly\")\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Summary\n", "\n", "Gantt charts in maxplotlib support:\n", "- Simple task timelines\n", "- Multiple phases with different colors\n", "- Resource allocation visualization\n", "- Milestones (zero-duration tasks)\n", "- All backends: matplotlib, plotly, plotext, tikzfigure\n", "- Customizable colors, transparency, and edge colors" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 4 }