Gannt Chart Python Code
Gannt Chart Python Code
plt.style.use('ggplot')
---------------------------
---------------------------
tasks = [ { "Task": "Market Research", "Start": "Feb 17, 2025", "End": "Mar 2,
2025", "Color": "#70AD47" # Planning Phase }, { "Task": "Two Domestic
Safari Package Development", "Start": "Mar 3, 2025", "End": "Mar 16, 2025",
"Color": "#70AD47" # Planning Phase }, { "Task": "Social Media Campaign",
"Start": "Mar 17, 2025", "End": "Apr 6, 2025", "Color": "#ED7D31" #
Implementation Phase }, { "Task": "Vehicle Optimization", "Start": "Mar 17,
2025", "End": "Apr 20, 2025", "Color": "#ED7D31" # Implementation
Phase }, { "Task": "Local Trip Highlights", "Start": "Mar 17, 2025", "End":
"Apr 6, 2025", "Color": "#ED7D31" # Implementation Phase }, { "Task":
"Repeat-Customer Discount Program", "Start": "Apr 7, 2025", "End": "May 11,
2025", "Color": "#ED7D31" # Implementation Phase }, { "Task": "Progress
Monitoring", "Start": "Mar 3, 2025", "End": "May 11, 2025", "Color":
"#FFC000" # Monitoring } ]
---------------------------
Define Milestones
---------------------------
---------------------------
---------------------------
---------------------------
Set y positions for tasks (reserve extra space at the top for milestones)
---------------------------
---------------------------
for dep in dependencies: source = tasks[dep["from"]] target =
tasks[dep["to"]] start_x = source["End_dt"] end_x = target["Start_dt"] start_y
= dep["from"] end_y = dep["to"] # Draw an arrow from the end of the
source task to the beginning of the target task. ax.annotate("", xy=(end_x,
end_y + 0.25), xytext=(start_x, start_y - 0.25),
arrowprops=dict(arrowstyle="->", color="gray", lw=1.5,
connectionstyle="arc3,rad=-0.3"))
---------------------------
---------------------------
---------------------------
---------------------------
ax.xaxis_date()
ax.xaxis.set_major_locator(mdates.WeekdayLocator(interval=1))
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %d"))
plt.xticks(rotation=45) plt.xlabel("Date") plt.ylabel("Tasks")
plt.title("Capstone Project Gantt Chart", fontsize=16, fontweight='bold')
ax.set_ylim(-0.75, num_tasks + 1)
---------------------------
Add a Legend
---------------------------
---------------------------
---------------------------
plt.tight_layout() plt.show()
-----------------------------------------------
-----------------------------------------------