Guide · 2026-12-05

How to Make a Gantt Chart in MATLAB: Step-by-Step Guide

Building a project schedule in MATLAB can feel harder than the work itself. You have task names and dates, but MATLAB does not give every project a ready-made Gantt chart workflow. A basic bar chart may also hide start dates, task overlaps, and the overall timeline.

That makes it easy to create a chart that looks neat but misrepresents when work happens. But here's the truth: you can build a clear Gantt chart with MATLAB’s barh function by plotting task durations as stacked horizontal bars. Here, I’ll show you how to prepare the dates, create the chart, and adjust its labels. You’ll also see how to handle common display issues and when a project management platform may be a better fit for coordinating the work behind the chart.

How to Make a Gantt Chart in MATLAB

The basic method is to calculate each task’s offset from the project start and its duration. Then, use a hidden bar for the offset and a visible bar for the task itself.

  1. List the tasks and their dates. Create one task name, start date, and end date for every activity. Keep the entries in the same order so each name matches its dates.

  2. Convert the dates to elapsed days. MATLAB can work with datetime values. Calculate the number of days between each start date and the earliest project date.

  3. Calculate each duration. For schedules where both the start and end dates count as work on the task, add one day to the date difference. For elapsed calendar time, leave that extra day out.

  4. Plot stacked horizontal bars. Use the start offset as the first bar segment and the task duration as the second. Hide the first segment so the visible segment begins on the correct date.

  5. Label and format the chart. Add task names to the vertical axis, dates to the horizontal axis, and a title. Check the task order and date labels before sharing the result.

Here’s a complete example. The dates are inclusive, so a task beginning and ending on the same date appears as a one-day bar.

tasks = ["Planning"; "Design"; "Build"; "Testing"; "Launch"];

startDates = datetime(["2025-03-03"; "2025-03-05"; ...
    "2025-03-10"; "2025-03-17"; "2025-03-24"], ...
    "InputFormat", "yyyy-MM-dd");

endDates = datetime(["2025-03-06"; "2025-03-12"; ...
    "2025-03-18"; "2025-03-21"; "2025-03-25"], ...
    "InputFormat", "yyyy-MM-dd");

projectStart = min(startDates);
startOffset = days(startDates - projectStart);
duration = days(endDates - startDates) + 1;
y = 1:numel(tasks);

figure;
bars = barh(y, [startOffset duration], "stacked");

bars(1).FaceColor = "none";
bars(1).EdgeColor = "none";
bars(2).FaceColor = [0.18 0.48 0.72];

ax = gca;
ax.YTick = y;
ax.YTickLabel = tasks;
ax.YDir = "reverse";

lastDay = max(startOffset + duration);
tickPositions = 0:2:lastDay;
tickDates = projectStart + days(tickPositions);

ax.XTick = tickPositions;
ax.XTickLabel = cellstr(datestr(tickDates, "mmm dd"));

xlim([0 lastDay + 1]);
xlabel("Date");
ylabel("Task");
title("Project Schedule");
grid on;
box on;

The first bar segment positions each task on the timeline; making it transparent leaves only the visible duration. Here's why: a standard horizontal bar starts at zero, while a Gantt bar needs to start on its own scheduled date.

How the Date Calculations Work

The chart’s horizontal axis uses elapsed days rather than displaying full date values directly. MATLAB calculates each task’s offset from the earliest start date, giving the bars a shared timeline.

For example, if the project starts on March 3 and a task starts on March 10, its offset is seven days. A duration of four days then places the visible bar across that task’s scheduled period.

Inclusive and elapsed durations

The example adds one to the difference between the end and start dates. That convention treats both dates as part of the task. A task running from March 3 through March 3 therefore occupies one day.

If your schedule treats the end date as the point when work finishes, calculate duration without adding one. Pick one convention and use it for every task; mixing conventions can make bars appear a day too long or too short.

Calendar days and workdays

The example counts calendar days, including weekends. That suits a schedule where tasks can continue every day, such as a system migration running through a weekend.

For a Monday-to-Friday schedule, calculate durations using workdays instead. MATLAB’s busdays function can help with business-day calculations, but holidays require separate handling. Decide whether holidays count before interpreting the displayed bar lengths.

Make the Chart Easier to Read

A chart can be mathematically correct and still difficult to scan. Clear labels, sensible spacing, and a useful date scale help someone understand the schedule without studying the code.

Choose date ticks that fit the schedule

The example labels every second day, which works for a short project. For a schedule spanning several months, weekly or monthly ticks will usually be easier to read.

Change the interval in tickPositions = 0:2:lastDay. For weekly ticks, use 0:7:lastDay. The date labels come from those positions, so update the interval rather than typing dates separately.

Keep task labels in a useful order

Setting YDir to reverse places the first task at the top, matching the order in the task list. Remove that setting if you prefer the first task at the bottom.

For a long schedule, shorten labels or widen the figure. A label such as “User acceptance testing” may need more room than “Build,” especially when you plan to show the chart in a presentation.

Use color with a purpose

The example uses one color for every task. If color adds meaning, assign it consistently, such as a different shade for each project phase. Include a legend when readers need help interpreting the colors.

Color should not carry information on its own. If red marks delayed tasks, also label or explain that status so the chart remains understandable when printed without color.

Add Milestones and Dependencies Carefully

A basic Gantt chart shows task timing and overlap, but it does not automatically understand project logic. If one activity depends on another, the schedule needs that relationship represented separately.

Show milestones as markers

A milestone is a point in time rather than a task with a multi-day duration. You can add one using a marker at its timeline position and task row, then label it in the chart.

For instance, place a marker on the launch date and label it “Release.” Use a distinct marker shape so the milestone is easy to distinguish from the duration bars.

Represent dependencies without implying automation

You can draw arrows between task bars to show relationships, but those arrows are visual annotations. They do not reschedule later tasks when an earlier date changes.

For example, if testing must begin after the build ends, the chart can show that connection. You still need to update the testing date yourself when the build schedule shifts, unless your scheduling workflow calculates dependencies.

Refresh the chart when dates change

Because the chart is generated from MATLAB variables, update the task dates and rerun the plotting commands after a schedule change. Check that the displayed labels and axis limits still match the new timeline.

This works well for a planned report or repeatable analysis. If several people need to update tasks throughout the week, manually rerunning a script can become an extra coordination step.

When MATLAB Is the Right Choice

MATLAB is a strong choice when you need control over how a schedule is calculated or displayed. You can combine task dates with project analysis, create consistent figures, and adjust the chart for a technical report.

It also suits a schedule that one person maintains or generates as part of a broader MATLAB workflow. For example, an engineering team might plot testing phases alongside results from a simulation.

But here's the trade-off: a plotted chart does not automatically become a shared task management process. If several people need to assign work, change statuses, or coordinate approvals, you may need a separate way to manage those activities.

Project Coordination Solution: ONES.com

ONES.com product screenshot

Value Proposition

ONES.com is a unified platform for project management and knowledge management, powered by ONES Assistant. ONES Project handles project management and can serve as a Jira alternative; ONES Wiki provides knowledge management as a Confluence alternative, and the products are sold separately.

MATLAB remains useful for building a custom Gantt chart. ONES Project addresses a different need: coordinating tasks and workflows so project information is easier for a team to maintain. It is not necessary to replace your MATLAB chart to use it for project coordination.

Core Capabilities

Application Scenarios

Engineering project with a MATLAB schedule: An engineer can use MATLAB to create a custom chart for a technical review while the team tracks task owners, statuses, and workflow stages in ONES Project. The chart supports analysis; the platform supports day-to-day coordination.

Multi-team release: A team managing design, development, and testing can use custom workflows and reporting to follow work across stages. If the team also needs shared project knowledge, it can use ONES Wiki separately from ONES Project.

ONES.com may fit teams that want project tracking and knowledge management under one platform, especially when deployment choices matter. It does not remove the need to define task dates or decide how a MATLAB chart should represent project timing.

Common Challenges and Practical Fixes

The bars begin at zero

Problem: A regular bar chart shows task durations but ignores their actual start dates. Every bar appears to begin at the project origin.

Solution: Use a stacked horizontal bar with a start-offset segment before the duration. Set the offset segment’s face and edge colors to none so it positions the visible bar without appearing in the chart.

The chart looks one day out of sync

Problem: A task’s bar appears a day shorter or longer than expected. This often happens when the duration convention is unclear.

Solution: Decide whether the end date is included as a working day. Add one to the date difference for inclusive dates; omit it when the end date marks the completion boundary.

Date labels overlap

Problem: A long project creates too many crowded tick labels. Readers may struggle to distinguish dates.

Solution: Increase the gap between tick positions, or widen the chart. Use a weekly or monthly interval for longer timelines instead of labeling every day.

Changes do not update dependent tasks

Problem: Moving one task leaves later tasks at their old dates. The chart displays the updated values but does not know the schedule’s dependency rules.

Solution: Recalculate dependent dates in your scheduling logic before plotting. If a team needs ongoing coordination, use a workflow that tracks tasks and their status alongside the chart.

Frequently Asked Questions

Does MATLAB have a built-in Gantt chart function?

You can create a Gantt-style chart in MATLAB with standard plotting functions such as barh. The example in this guide uses stacked bars to position task durations on a shared timeline. This approach gives you control over labels and formatting without relying on a dedicated Gantt chart function.

How do I show overlapping tasks?

Give each task its own row and calculate its start offset from the same project start date. Tasks with overlapping dates will then appear as bars occupying the same horizontal timeline period on different rows. Confirm that each row has a unique vertical position so overlapping work remains visible.

Can I use MATLAB to show weekends or holidays?

Yes. The example uses calendar days, so weekends appear as part of the timeline. For business-day schedules, calculate durations with workday logic and decide how holidays should be handled. A chart’s date scale and its duration calculation should follow the same calendar convention.

How can I save or share the chart?

You can use MATLAB’s figure export options to create an image or other supported output for a report or presentation. Check the text size and date labels at the final display size before sharing. If teammates need to update task ownership and status, a static chart alone may not provide the coordination they need.

Conclusion

To make a Gantt chart in MATLAB, calculate each task’s start offset and duration, then plot them as stacked horizontal bars. Hide the offset segment, label the axes, and choose date ticks that suit the schedule.

Check whether your durations include both start and end dates, and remember that a chart does not automatically manage task dependencies. MATLAB gives you control over custom visualizations; a project management workflow can help when several people need to maintain the schedule.

When a basic bar chart leaves dates unclear, the offset-and-duration method solves the central problem. Start with the sample code, adapt the dates to your project, and adjust the chart until someone can read the schedule at a glance.