GanttChart
A schedule: one bar per task from its start to its end over a date axis. The Gantt Chart guide shows every feature on real data; this page is the contract: the function, the shape of its data, the keys style takes, and the constant each parameter accepts.
Function
datachart.charts.GanttChart
GanttChart(
data: list[GanttTaskAttrs] | list[list[GanttTaskAttrs]],
*,
title: str | None = None,
xlabel: str | None = None,
ylabel: str | None = None,
subtitle: str | list[str | None] | None = None,
figsize: FIG_SIZE | tuple[float, float] | None = None,
xmin: date | datetime | None = None,
xmax: date | datetime | None = None,
max_cols: int | None = None,
period: GANTT_DATE_PERIOD | str | None = None,
show_group_headers: bool | None = None,
show_legend: bool | None = None,
legend: LegendSettingAttrs | None = None,
show_grid: SHOW_GRID | str | bool | None = None,
show_values: GANTT_VALUE | str | None = None,
value_format: VALUE_FORMAT | str | None = None,
show_dependencies: bool | None = None,
show_today: bool | None = None,
today: date | datetime | None = None,
today_label: str | None = None,
sort: SORT | str | None = None,
sort_by: GANTT_SORT_KEY | str | None = None,
emphasis: (
EMPHASIS | str | list[str | None] | None
) = None,
emphasis_rule: EmphasisRuleAttrs | None = None,
style: (
GanttStyleAttrs
| list[GanttStyleAttrs | None]
| None
) = None,
xtickrotate: int | None = None,
ytickrotate: int | None = None,
xticks_format: DATE_FORMAT | str | None = None,
vlines: (
VLineSettingAttrs | list[VLineSettingAttrs] | None
) = None,
vspans: (
VSpanSettingAttrs | list[VSpanSettingAttrs] | None
) = None,
texts: (
TextSettingAttrs | list[TextSettingAttrs] | None
) = None
) -> plt.Figure
Creates the gantt chart.
A gantt chart shows a schedule: one horizontal bar per task from its start to its end over a date axis, one row per task, the first task at the top. Use it for project plans, release roadmaps, or any set of activities where when and how long matter more than a single value. Task groups share a colour or get header rows with summary bars, an optional progress fraction fills part of each bar, a task ending when it starts is a milestone marker, dependency arrows link tasks, the date axis can be divided into calendar periods, and a today line marks the present.
The chart is always horizontal, so the axis parameters are spatial:
xlabel, xmin, xmax, and xticks_format address the horizontal date
axis, and ylabel the vertical task axis. It composes in Grid, but not
in Panel.
Examples:
>>> from datetime import date
>>> from datachart.charts import GanttChart
>>> figure = GanttChart(
... data=[
... {"task": "Design", "start": date(2024, 1, 1), "end": date(2024, 1, 12),
... "group": "Plan", "progress": 1.0},
... {"task": "Build", "start": date(2024, 1, 10), "end": date(2024, 2, 9),
... "group": "Make", "progress": 0.4, "depends_on": ["Design"]},
... {"task": "Test", "start": date(2024, 2, 5), "end": date(2024, 2, 23),
... "group": "Make", "depends_on": ["Build"]},
... ],
... title="Release Plan",
... show_dependencies=True,
... )
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The task records of the schedule: a list of
TYPE:
|
title
|
The title of the chart.
TYPE:
|
xlabel
|
The label of the horizontal date axis.
TYPE:
|
ylabel
|
The label of the vertical task axis.
TYPE:
|
subtitle
|
The subtitle of each schedule.
TYPE:
|
figsize
|
The size of the figure as (width, height) in inches. See
TYPE:
|
xmin
|
The start of the date window, as a temporal object.
TYPE:
|
xmax
|
The end of the date window, as a temporal object.
TYPE:
|
max_cols
|
The maximum number of subplot columns for several schedules.
TYPE:
|
period
|
The calendar period the date axis is divided into: None (concise date
ticks), "day", "week", "month", "quarter", "year", or "project_month" (M1,
M2, … from
TYPE:
|
show_group_headers
|
Whether to give each task group a header row with
a summary bar from its first start to its last end, the group's
rows clustered beneath it and a gap before the next group. Raises
when no task carries a
TYPE:
|
show_legend
|
Whether to show the legend of the task groups. Defaults
to on when any task carries a
TYPE:
|
legend
|
The per-figure legend setting: title, location, column count
and alignment; each field falls back to the theme. See
TYPE:
|
show_grid
|
Which grid lines to show ("both", "x", "y");
TYPE:
|
show_values
|
The label printed past each bar end: None (none),
TYPE:
|
value_format
|
Format string for the value labels: a
TYPE:
|
show_dependencies
|
Whether to draw an arrow from the end of each task
named in
TYPE:
|
show_today
|
Whether to draw the today line.
TYPE:
|
today
|
The date of the today line; the current date when not given.
TYPE:
|
today_label
|
The text printed at the foot of the today line; none when not given.
TYPE:
|
sort
|
The order of the task rows: None (input order), "ascending",
or "descending" by the key
TYPE:
|
sort_by
|
The key
TYPE:
|
emphasis
|
The emphasis role of the whole schedule ("background" or "highlight"),
or one role per schedule. See
TYPE:
|
emphasis_rule
|
A one-key dict that highlights the tasks matching it and mutes
the rest:
TYPE:
|
style
|
Style configuration(s) for the schedule. See
TYPE:
|
xtickrotate
|
Rotation angle for the date-axis tick labels.
TYPE:
|
ytickrotate
|
Rotation angle for the task-axis tick labels.
TYPE:
|
xticks_format
|
The date-axis tick label format: a
TYPE:
|
vlines
|
Vertical line(s) to plot, at temporal
TYPE:
|
vspans
|
Vertical reference band(s) to shade, between two temporal positions.
TYPE:
|
texts
|
Text annotation(s) to draw.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
plt.Figure
|
The figure containing the gantt chart. |
Data
Each record in data is a GanttTaskAttrs; the emphasis parameter renames its keys.
datachart.typings.GanttTaskAttrs
Bases: TypedDict
The task record attributes for the gantt chart.
| ATTRIBUTE | DESCRIPTION |
|---|---|
task |
The task name, unique within the chart; the label of its row.
TYPE:
|
start |
When the task starts: a
TYPE:
|
end |
When the task ends, of the same temporal types; never before
TYPE:
|
group |
The task group; tasks of one group share a color and a legend entry.
TYPE:
|
progress |
The fraction of the task done, in
TYPE:
|
depends_on |
The names of the tasks this task depends on.
TYPE:
|
emphasis |
The task's own emphasis role ("background" or "highlight"); wins over the chart's
TYPE:
|
Style
style takes the keys of GanttStyleAttrs. The chart also reads the shared groups it draws: value labels (ValueLabelStyleAttrs), reference lines (VLineStyleAttrs and HLineStyleAttrs), reference bands (VSpanStyleAttrs and HSpanStyleAttrs) and text annotations (TextStyleAttrs). Every key falls back to the theme, so the same keys set the default look through config.
datachart.typings.GanttStyleAttrs
Bases: TypedDict
The typing for the gantt chart style.
The range bars take the plot_bar_* keys (color, alpha, edge, hatch,
zorder); these keys set what is specific to a gantt chart.
| ATTRIBUTE | DESCRIPTION |
|---|---|
plot_gantt_bar_height |
The height of a task bar, as a fraction of its row.
TYPE:
|
plot_gantt_progress_color |
The color of the progress bar;
TYPE:
|
plot_gantt_progress_alpha |
The alpha value of the progress bar.
TYPE:
|
plot_gantt_progress_height |
The height of the progress bar, as a fraction of the task bar.
TYPE:
|
plot_gantt_dependency_color |
The color of the dependency arrows.
TYPE:
|
plot_gantt_dependency_width |
The line width of the dependency arrows.
TYPE:
|
plot_gantt_dependency_style |
The arrow head of the dependency arrows, as a matplotlib arrow style.
TYPE:
|
plot_gantt_dependency_zorder |
The zorder of the dependency arrows.
TYPE:
|
plot_gantt_dependency_entry |
The side of the dependent task a dependency arrow enters ("top" or "left").
TYPE:
|
plot_gantt_summary_height |
The height of a group's summary bar under
TYPE:
|
plot_gantt_summary_color |
The color of the summary bars;
TYPE:
|
plot_gantt_group_gap |
The empty space before each group header, in rows.
TYPE:
|
plot_gantt_milestone_marker |
The marker of a milestone, a task whose
TYPE:
|
plot_gantt_milestone_size |
The size of the milestone marker, in points.
TYPE:
|
plot_gantt_today_color |
The color of the today line.
TYPE:
|
plot_gantt_today_style |
The line style of the today line.
TYPE:
|
plot_gantt_today_width |
The line width of the today line.
TYPE:
|
plot_gantt_today_alpha |
The alpha value of the today line.
TYPE:
|
Constants
The parameters that accept a constant, with the class in datachart.constants that lists its values.
| Parameter | Constant |
|---|---|
period |
GANTT_DATE_PERIOD |
show_values |
GANTT_VALUE |
sort_by |
GANTT_SORT_KEY |
style={"plot_gantt_dependency_entry": ...} |
GANTT_ARROW_ENTRY |
figsize |
FIG_SIZE |
legend={"location": ..., "alignment": ...} |
LEGEND_LOCATION, LEGEND_ALIGN |
show_grid |
SHOW_GRID |
value_format |
VALUE_FORMAT |
sort |
SORT |
emphasis |
EMPHASIS |
xticks_format |
DATE_FORMAT |