This page is part of the ScottPlot 5.0 Cookbook
⚠️ ScottPlot 5.0.8-beta is a preview package
This page describes a beta release of ScottPlot. It is available on NuGet as a preview package, but its API is not stable and it is not recommended for production use. See the ScottPlot Versions page for more information.
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}";
else
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;
myPlot.SavePng("custom-tick-formatters.png");
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.Add.Signal(Generate.Sin(51));
myPlot.Add.Signal(Generate.Cos(51));
myPlot.XAxis.TickGenerator = new ScottPlot.TickGenerators.NumericFixedInterval(11);
myPlot.SavePng("custom-tick-generators.png");