Custom Tick Formatters
Users can customize the logic used to create tick labels from tick positions. Old versions of ScottPlot achieved this using a ManualTickPositions method.
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.Axes.Bottom.TickGenerator = myTickGenerator;
myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the Customizing Ticks category
