Skip to content

Instantly share code, notes, and snippets.

@ishank-dev
Created October 31, 2024 00:36
Show Gist options
  • Save ishank-dev/12c3fc7b2b2ab10bb239f55ba59e0b4a to your computer and use it in GitHub Desktop.
Save ishank-dev/12c3fc7b2b2ab10bb239f55ba59e0b4a to your computer and use it in GitHub Desktop.
Plot Gantt Chart Using JSON
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from datetime import datetime
import pandas as pd
task_data = {
"Task Name": [
"Project Setup and Environment Configuration", "Design UI and Dashboard",
"Develop Home Screen and Dashboard", "Implement Navigation Logic",
"Develop Program Management Module", "Develop Area Management Module",
"Develop Employee Management Module", "Integrate Management Modules",
"Develop New Bug Entry Form", "Develop Bug Search Functionality",
"Develop Bug Results Page", "Develop Update Bug Form",
"Integrate Bug Management Features", "Develop Database Maintenance Page",
"Testing and Quality Assurance", "Final Deployment and Documentation"
],
"Start Date": [
"2024-10-30", "2024-10-30", "2024-11-05", "2024-11-08",
"2024-11-10", "2024-11-10", "2024-11-10", "2024-11-14",
"2024-11-16", "2024-11-16", "2024-11-20", "2024-11-20",
"2024-11-23", "2024-11-16", "2024-11-25", "2024-12-01"
],
"End Date": [
"2024-10-31", "2024-11-04", "2024-11-07", "2024-11-09",
"2024-11-12", "2024-11-12", "2024-11-13", "2024-11-15",
"2024-11-19", "2024-11-19", "2024-11-22", "2024-11-22",
"2024-11-24", "2024-11-18", "2024-11-30", "2024-12-02"
]
}
df_tasks = pd.DataFrame(task_data)
df_tasks["Start Date"] = pd.to_datetime(df_tasks["Start Date"])
df_tasks["End Date"] = pd.to_datetime(df_tasks["End Date"])
df_tasks["Duration"] = df_tasks["End Date"] - df_tasks["Start Date"]
colors = ["#FF9999", "#66B2FF", "#99FF99", "#FFCC99", "#FF6666", "#66FFB2", "#FFB266", "#B266FF",
"#FF66B2", "#66FF66", "#9999FF", "#FF66FF", "#FF9966", "#B2FF66", "#66B2FF", "#FFB2FF"]
fig, ax = plt.subplots(figsize=(12, 8))
for i, task in df_tasks.iterrows():
color = colors[i % len(colors)]
ax.barh(task["Task Name"], task["Duration"].days, left=task["Start Date"], align='center', color=color, edgecolor="black")
ax.text(task["Start Date"] + task["Duration"] / 2, i, f"{task['Duration'].days}d", va='center', ha='center', color="black")
ax.xaxis.set_major_locator(mdates.WeekdayLocator(interval=1))
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %d"))
plt.xlabel("Date")
plt.ylabel("Tasks")
plt.title("Project Schedule Gantt Chart with Individual Colors")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment