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();

var ys = SampleData.Faithful;

var hist = Histogram.WithBinCount(80, ys);

var histPlot = myPlot.Add.Histogram(hist);
histPlot.BarWidthFraction = 0.8;
foreach (var bar in histPlot.Bars)
{
    bar.FillColor = Colors.LightBlue;
}

foreach (var kernel in Enum.GetValues<KdeKernel>())
{
    var densityEstimate = hist.Bins.Select((x, i) => KernelDensity.Estimate(x, ys, kernel)).ToArray();
    double scale = ys.Length;

    var rescaledDensityEstimate = densityEstimate.Select(x => x * scale).ToArray();

    var scat = myPlot.Add.Scatter(hist.Bins, rescaledDensityEstimate);
    scat.MarkerSize = 0;
    scat.LegendText = kernel.ToString();
}

myPlot.SavePng("demo.png", 400, 300);
このレシピは、カーネル密度推定カテゴリに含まれる多数のレシピの 1 つです