Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

カラーバーの目盛りフォーマッター

カラーバーには、ユーザーが目盛りラベルの文字列形式を制御できる、オプションのカスタム目盛りフォーマッターがあります。

Heatmap.cs
ScottPlot.Plot myPlot = new();

double[,] data = SampleData.MonaLisa();

var hm = myPlot.Add.Heatmap(data);
var cb = myPlot.Add.ColorBar(hm);
cb.MinimumSize = 80; // カラーバーと目盛りラベルのためのスペースを確保する

// 文字列フォーマットのロジックを含む静的関数を作成する
static string CustomFormatter(double position)
{
    return $"{Math.Round(position / 2.55)} %";
}

// カスタムラベルフォーマッターを使用してカスタム目盛りジェネレーターを作成する
ScottPlot.TickGenerators.NumericAutomatic myTickGenerator = new()
{
    LabelFormatter = CustomFormatter
};

// カラーバーにカスタム目盛りジェネレーターを使用するよう指示する
cb.Axis.TickGenerator = myTickGenerator;

myPlot.SavePng("demo.png", 400, 300);
このレシピは、ヒートマップカテゴリにある多数のレシピの 1 つです