Skip to content

Heatmap user-provided extent off by one cell #3434

@BrianAtZetica

Description

@BrianAtZetica

Issue: When the user provides extents for a heatmap, they will be thinking about the first and last data value coordinate.
Currently this will be misinterpreted, with an off-by-one error on the maximum extent.

ScottPlot Version: SP5 (nuget 5.0.21 and main github branch)

In sample code belwo user has a 2 x 3 array of data. They will want the heatmap cell centres to be aligned on integer axes, so they set extents of 0,1,0,2

        double[,] data = { { 1, 2 }, { 3, 4 } , { 5, 6 } };
        var hm1 = WpfPlot1.Plot.Add.Heatmap(data);
        hm1.CellAlignment = Alignment.MiddleCenter;

        // User defines an X extent of 0 to 1 (intending the first column on 0 and the second column on 1).
        // User defines an Y extent of 0 to 2 (intending the first row on 0 and last row on 2).
        hm1.Extent = new(0, 1, 0, 2);
        hm1.FlipRows = false;
        hm1.FlipColumns = false;
        WpfPlot1.Plot.Axes.SetLimits(-1.2, 2.2, -1.2, 3.2);
        WpfPlot1.Plot.Title("Default Image Orientation");
        hm1.Smooth = false;
        WpfPlot1.Plot.SavePng("2x3 grid Default.png", 300, 400);

Actual Output:
2x3 grid Default

Expected Output:

2x3 grid Default

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions