Skip to content

Add CoordinatedHeatmap#707

Merged
swharden merged 4 commits intoScottPlot:masterfrom
StendProg:CoordinatedHeatmap
Feb 5, 2021
Merged

Add CoordinatedHeatmap#707
swharden merged 4 commits intoScottPlot:masterfrom
StendProg:CoordinatedHeatmap

Conversation

@StendProg
Copy link
Contributor

@StendProg StendProg commented Jan 23, 2021

Purpose:
Allows to use an existing coordinate system to get additional coordinate information about HeatMap. #701

Additionaly Fix ColorBar, with this PR it will not affect AxisLimits calculation.

New Functionality:
User can provide coordinated boundaries for provided rectangular distribution.
Missing bounds are calculated based on the size of the intensities array.

double[,] intensities = ....; 

var hmc = plt.AddHeatmapCoordinated(intensities, -100, 500, 200, 201);

var hmc1 = plt.AddHeatmapCoordinated(intensities, xMin: -100, yMax: 50);

image

Fix ColorBar affect AxisLimits calculation.
@swharden swharden mentioned this pull request Jan 26, 2021
48 tasks
@swharden
Copy link
Member

swharden commented Feb 5, 2021

Thanks @StendProg! This behavior is a lot more consistent with heatmaps I've interacted with in the past. This is a very useful addition.

/// <summary>
/// Add coordinated heatmap to the plot
/// </summary>
public CoordinatedHeatmap AddHeatMapCoordinated(double[,] intensities, double? xMin = null, double? xMax = null, double? yMin = null, double? yMax = null, Drawing.Colormap colormap = null)
{
var plottable = new CoordinatedHeatmap();
// Solve all possible null combinations, if the boundaries are only partially provided use Step = 1;
if (xMin == null && xMax == null)
{
plottable.XMin = 0;
plottable.XMax = 0 + intensities.GetLength(0);
}
else if (xMin == null)
{
plottable.XMax = xMax.Value;
plottable.XMin = xMax.Value - intensities.GetLength(0);
}
else if (xMax == null)
{
plottable.XMin = xMin.Value;
plottable.XMax = xMin.Value + intensities.GetLength(0);
}
else
{
plottable.XMin = xMin.Value;
plottable.XMax = xMax.Value;
}
if (yMin == null && yMax == null)
{
plottable.YMin = 0;
plottable.YMax = 0 + intensities.GetLength(1);
}
else if (yMin == null)
{
plottable.YMax = yMax.Value;
plottable.YMin = yMax.Value - intensities.GetLength(1);
}
else if (yMax == null)
{
plottable.YMin = yMin.Value;
plottable.YMax = yMin.Value + intensities.GetLength(1);
}
else
{
plottable.YMin = yMin.Value;
plottable.YMax = yMax.Value;
}
plottable.Update(intensities, colormap);
Add(plottable);
return plottable;
}

I am considering removing the nullable min/max arguments, and forcing the user to define all 4 values when adding a coordinated heatmap. This could remove a lot of that null-checking code, but the main reason I think this may be a good idea is because it is not very obvious what passing null actually does without reading the source code.

Perhaps an intermediate option could be to force the user to define the upper limits, while the lower limits default to zero.

AddHeatMapCoordinated(double[,] intensities, double xMax, double yMax, double xMin = 0, double yMin = 0) 

I probably won't make the change until later when I finish working on other parts of the API, but if you feel strongly about what you think the best type of arguments I'd appreciate your input! Thanks again for this PR 👍

@swharden swharden merged commit 0b3cdbf into ScottPlot:master Feb 5, 2021
@swharden swharden mentioned this pull request May 17, 2021
82 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants