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

固定サイズのビンを使用したヒストグラム

ヒストグラムは、手動で定義したビンサイズを使用して作成できます。

ScottPlot.Plot myPlot = new();

// 値のコレクションからヒストグラムを作成する
double[] heights = SampleData.MaleHeights();
var hist = ScottPlot.Statistics.Histogram.WithBinSize(2, heights);

// ヒストグラムを棒グラフとして表示する
var barPlot = myPlot.Add.Bars(hist.Bins, hist.Counts);

// 各棒のサイズをビンの幅よりわずかに小さくする
foreach (var bar in barPlot.Bars)
{
    bar.Size = hist.FirstBinSize * .8;
}

// プロットのスタイルをカスタマイズする
myPlot.Axes.Margins(bottom: 0);
myPlot.YLabel("人数");
myPlot.XLabel("身長 (cm)");

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