Untitled
# Reducing the number of x-axis labels to make the dates more readable # Select only a subset of dates for labeling (e.g., every 5th workday) label_indices = range(0, len(work_days), 5) label_dates = [work_days[i] for i in label_indices] # Create the Gantt chart with reduced x-axis labels fig, ax = plt.subplots(figsize=(14, 8)) y_positions = range(len(tasks)) # Add tasks to the chart for i, (start, end) in enumerate(zip(start_dates, end_dates)): task_days = exclude_weekends(start, end) if task_days: ax.barh( y_positions[i], len(task_days), left=work_days.index(task_days[0]), color="skyblue", edgecolor="black", ) # Set the x-axis ticks and labels ax.set_xticks([work_days.index(date) for date in label_dates]) ax.set_xticklabels([date.strftime("%d-%b") for date in label_dates], rotation=45, ha="right") # Format the chart ax.set_yticks(y_positions) ax.set_yticklabels(short_task_names) plt.xlabel("Timeline") plt.ylabel("Tasks") plt.title("Project Gantt Chart: Workdays (August - December)") plt.tight_layout() # Show the updated chart plt.show()
Leave a Comment