ScottPlot.NET
GitHub Repo stars

Custom Tick DateTimes

Users may define custom ticks using DateTime units

ScottPlot.Plot myPlot = new();

DateTime[] dates = Generate.ConsecutiveDays(100);
double[] values = Generate.RandomWalk(100);
myPlot.Add.Scatter(dates, values);

// create a manual DateTime tick generator and add ticks
ScottPlot.TickGenerators.DateTimeManual ticks = new();

// add ticks for Mondays only
foreach (DateTime date in dates)
{
    if (date.DayOfWeek == DayOfWeek.Monday)
    {
        string label = date.DayOfYear.ToString();
        ticks.AddMajor(date, label);
    }
}

// tell the horizontal axis to use the custom tick generator
myPlot.Axes.Bottom.TickGenerator = ticks;

// style the plot
myPlot.Title("Monday Ticks");
myPlot.XLabel("Day of the Year");

myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the Customizing Ticks category