Colorbar Tick Formatter
Colorbars have an optional custom tick formatter that allows users to control the string format of tick labels.
ScottPlot.Plot myPlot = new();
double[,] data = SampleData.MonaLisa();
var hm = myPlot.Add.Heatmap(data);
var cb = myPlot.Add.ColorBar(hm);
cb.MinimumSize = 80; // reserve space for the colorbar and tick labels
// create a static function containing the string formatting logic
static string CustomFormatter(double position)
{
return $"{Math.Round(position / 2.55)} %";
}
// create a custom tick generator using your custom label formatter
ScottPlot.TickGenerators.NumericAutomatic myTickGenerator = new()
{
LabelFormatter = CustomFormatter
};
// tell the colorbar to use the custom tick generator
cb.Axis.TickGenerator = myTickGenerator;
myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the Heatmap category
