8
$\begingroup$

Fixed in 13.0

Background

Following up on how TimelinePlot can be used to plot GanttCharts (176012) I noted some peculiarities with the way TimelinePlot automatically draws Ticks and Gridlines.

Minimum Examples

Here are two simple examples that demonstrate, that Ticks and Gridlines are dependent on the length of some labels.

Now let's plot a simple project schedule using TimelinePlot:

$schedule1 = {
    Labeled[Interval[{DateObject[{2020, 10, 1}], DateObject[{2021, 10, 1}]}], "Step 1", Bottom], 
    Labeled[Interval[{DateObject[{2021, 4, 1}], DateObject[{2022, 4, 1}]}], "Step 2", Bottom],
    Labeled[Interval[{DateObject[{2022, 4, 1}], DateObject[{2023, 4, 1}]}], "Step 3", Bottom],
    Labeled[Interval[{DateObject[{2023, 4, 1}], DateObject[{2023, 10, 1}]}], "Step 4", Bottom]
};

$chart1 = TimelinePlot[ $schedule1,
    AxesOrigin -> Top,
    GridLines -> {Automatic, None},
    PlotLayout -> "Stacked",
    DateTicksFormat -> {"MonthNameShort", " ", "YearShort"}
]

Gantt Chart1

That looks reasonable enough: The gridlines separate the years and the ticks are drawn every two months.

Let's now plot the same schedule, but now we rename Step 4 to the longer Implementation:

$schedule2 = {
    Labeled[Interval[{DateObject[{2020, 10, 1}], DateObject[{2021, 10, 1}]}], "Step 1", Bottom], 
    Labeled[Interval[{DateObject[{2021, 4, 1}], DateObject[{2022, 4, 1}]}], "Step 2", Bottom],
    Labeled[Interval[{DateObject[{2022, 4, 1}], DateObject[{2023, 4, 1}]}], "Step 3", Bottom],
    Labeled[Interval[{DateObject[{2023, 4, 1}], DateObject[{2023, 10, 1}]}], "Implementation", Bottom]
}; 

$chart2 = TimelinePlot[ $schedule2,
    AxesOrigin -> Top,
    GridLines -> {Automatic, None},
    PlotLayout -> "Stacked",
    DateTicksFormat -> {"MonthNameShort", " ", "YearShort"}
]

Gantt Chart2

This does not look right or at least not nice. Note, that using the following explicit sepcification for GridLines will give the exact same result:

GridLines -> {DateRange[{2021, 1, 1}, {2024, 1, 1}, Quantity[12, "Months"]], None}

So, in $chart2 the month January obviously extends from the small tick to the left to the small tick to the right of any label Jan 2x, but the gridlines that are supposed to mark the first day of each January sit right in the middle of that month.

Is this a bug? And what can be done about this?

$\endgroup$

1 Answer 1

2
$\begingroup$

I just received an answer from Wolfram's Technical Support, which suggest a workaround around the issue at hand.

Adding an explicit PlotRange will fix the issue with the minor ticks:

$chart2WithPlotRange = TimeLinePlot[ $schedule2,
    AxesOrigin -> Top,
    GridLines -> {Automatic, None},
    PlotLayout -> "Stacked",
    DateTicksFormat -> {"MonthNameShort", " ", "YearShort"},
    PlotRange -> {"October 1, 2020", "October 1, 2023"}
]

Gantt Chartt with workaround

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.