-
Notifications
You must be signed in to change notification settings - Fork 981
Closed
Description
I'm struggling with installing a second colorbar to a plot. It seems like the heatmap on a plot can have only single colorbar, so I made two inherited classes (codes bellow) to add an additional colorbar to the plot.
When adding the second colorbar, there's an enexpected space between the color bar and the scale bar.(as in the attached picture)
I'm wondering if there's any tips to fix this?
public class CustomColorBar : IHasColorAxis
{
public CustomColorBar() { }
public CustomColorBar(CustomColorMap palette)
{
Colormap = palette;
}
public void SetColorMap(CustomColorMap palette)
{
Colormap = palette;
}
private IColormap _colormap { get; set; }
public IColormap Colormap
{
get { return _colormap; }
set { _colormap = value; }
}
private ScottPlot.Range _range { get; set; }
public ScottPlot.Range Range
{
get { return _range; }
set { _range = value; }
}
public void SetRange(double min, double max) { _range = new ScottPlot.Range(min, max); }
public ScottPlot.Range GetRange() { return Range; }
}
public class CustomColorMap : IColormap
{
public CustomColorMap() { }
public CustomColorMap(uint[] colors)
{
Colors = colors;
}
private uint[] _colors { get; set; } = new uint[256];
public uint[] Colors
{
get { return _colors; }
set { _colors = value; }
}
public string Name => "CustomColor";
public ScottPlot.Color GetColor(double position)
{
int index = (int)(position * _colors.Length);
if (index < 0) index = 0;
if (index > 255) index = 255;
return ScottPlot.Color.FromARGB(Colors[index]);
}
public ScottPlot.Color GetColor(double position, ScottPlot.Range range)
{
double cRange = range.Max - range.Min;
int index = (int)((position - range.Min) * 256 / cRange);
if (index < 0) index = 0;
if (index > 255) index = 255;
return ScottPlot.Color.FromARGB(Colors[index]);
}
}
,,,,
```cs
ScottPlot.Color[] myColors = new ScottPlot.Color[256];
for (int i = 0; i < myColors.Length; i++)
{
_colors[i] = myColors[i].ARGB;
}
var myMap = new CustomColorMap(_colors);
_vectorColorBarAxes = new CustomColorBar(myMap);
_vectorColorBarAxes.SetRange(5, 15);
_vectorColorBar = MyPlot.Plot.Add.ColorBar(_vectorColorBarAxes, Edge.Right);
_vectorColorBar.Margin = 240;Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
