Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.9 kB
1
Indexable
Never
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.dates as mdates

# Define the project tasks and their start and end dates
tasks = [
    {"Task": "Project Start", "Start": "2024-02-12", "Finish": "2024-02-12", "Color": "tab:blue"},
    {"Task": "Define (D)", "Start": "2024-02-12", "Finish": "2024-02-21", "Color": "tab:orange"},
    {"Task": "Measurement (M)", "Start": "2024-02-21", "Finish": "2024-02-28", "Color": "tab:green"},
    {"Task": "Analysis (A)", "Start": "2024-02-28", "Finish": "2024-03-13", "Color": "tab:red"},
    {"Task": "Improvement (I)", "Start": "2024-03-13", "Finish": "2024-03-27", "Color": "tab:purple"},
    {"Task": "Implement (I)", "Start": "2024-03-27", "Finish": "2024-04-10", "Color": "tab:brown"},
    {"Task": "Control (C)", "Start": "2024-04-10", "Finish": "2024-04-24", "Color": "tab:pink"},
    {"Task": "Project Completion", "Start": "2024-04-24", "Finish": "2024-05-29", "Color": "tab:gray"},
]

# Create a DataFrame
df = pd.DataFrame(tasks)

# Convert dates
df['Start'] = pd.to_datetime(df['Start'])
df['Finish'] = pd.to_datetime(df['Finish'])
df['Duration'] = df['Finish'] - df['Start']

# Plotting
fig, ax = plt.subplots(figsize=(10, 5))

# Remove the borders
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)

# Remove the y-axis
ax.yaxis.set_visible(False)

# Add gridlines
ax.xaxis.grid(True, linestyle='--', which='both', color='grey', alpha=0.5)

# Set x-axis as date
ax.xaxis_date()
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %d"))

# Create the bars
for i, task in df.iterrows():
    ax.barh(task['Task'], task['Duration'].days, left=task['Start'], color=task['Color'], edgecolor='black')

plt.title('Gantt Chart for Project "Manuales de operación y mantenimiento de la impresora \'Elder\'"')
plt.tight_layout()
plt.show()
Leave a Comment