Advanced customization of tick marks and tick labels

This page is part of the ScottPlot 5.0 Cookbook

Custom Tick Formatters

Users can customize the logic used to create tick labels from tick positions.

ScottPlot.Plot myPlot = new();

double[] xs = Generate.Consecutive(100, 1, -50);
myPlot.Add.Scatter(xs, Generate.Sin(100));
myPlot.Add.Scatter(xs, Generate.Cos(100));

// create a static function containing the string formatting logic
static string CustomFormatter(double position)
    if (position == 0)
        return "0";
    else if (position > 0)
        return $"+{position}";
        return $"({-position})";

// create a custom tick generator using your custom label formatter
ScottPlot.TickGenerators.NumericAutomatic myTickGenerator = new()
    LabelFormatter = CustomFormatter

// tell an axis to use the custom tick generator
myPlot.XAxis.TickGenerator = myTickGenerator;


Custom Tick Generators

Tick generators determine where ticks are to be placed and also contain logic for generating tick labels from tick positions. Alternative tick generators can be created and assigned to axes. Some common tick generators are provided with ScottPlot, and users also have the option create their own.

ScottPlot.Plot myPlot = new();


myPlot.XAxis.TickGenerator = new ScottPlot.TickGenerators.NumericFixedInterval(11);