public void Create_NotAvailableName_ReturnDefaultAlgae(string Name) { var factory = new ColormapFactory(); ScottPlot.Drawing.Colormap result = factory.Create(Name); Assert.AreEqual("Algae", result.Name); }
public Heatmap PlotHeatmap( double?[,] intensities, Drawing.Colormap colormap = null, string label = null, double[] axisOffsets = null, double[] axisMultipliers = null, double?scaleMin = null, double?scaleMax = null, double?transparencyThreshold = null, Bitmap backgroundImage = null, bool displayImageAbove = false, bool drawAxisLabels = true ) { Heatmap heatmap = new Heatmap() { Label = label, AxisOffsets = axisOffsets ?? new double[] { 0, 0 }, AxisMultipliers = axisMultipliers ?? new double[] { 1, 1 }, TransparencyThreshold = transparencyThreshold, BackgroundImage = backgroundImage, DisplayImageAbove = displayImageAbove, ShowAxisLabels = drawAxisLabels, }; heatmap.Update(intensities, colormap ?? Drawing.Colormap.Viridis, scaleMin, scaleMax); Add(heatmap); Layout(top: 180); return(heatmap); }
public void Create_NotAvailableName_ReturnDefaultAlgae(string Name) { var factory = new ColormapFactory(); ScottPlot.Drawing.Colormap result = factory.CreateOrDefault(Name); Assert.AreEqual(factory.GetDefaultColormap().GetType().Name, result.Name); }
public Heatmap PlotHeatmap( double[,] intensities, Drawing.Colormap colormap = null, string label = null, double[] axisOffsets = null, double[] axisMultipliers = null, double?scaleMin = null, double?scaleMax = null, double?transparencyThreshold = null, Bitmap backgroundImage = null, bool displayImageAbove = false, bool drawAxisLabels = true ) { double?[,] tmp = new double?[intensities.GetLength(0), intensities.GetLength(1)]; for (int i = 0; i < intensities.GetLength(0); i++) { for (int j = 0; j < intensities.GetLength(1); j++) { tmp[i, j] = intensities[i, j]; } } return(PlotHeatmap(tmp, colormap, label, axisOffsets, axisMultipliers, scaleMin, scaleMax, transparencyThreshold, backgroundImage, displayImageAbove, drawAxisLabels)); }
public static Bitmap Colorbar(Colormap cmap, int width, int height, bool vertical = false) { if (width < 1 || height < 1) { return(null); } Bitmap bmp = new Bitmap(width, height); using (Graphics gfx = Graphics.FromImage(bmp)) using (Pen pen = new Pen(Color.Magenta)) { if (vertical) { for (int y = 0; y < height; y++) { double fraction = (double)y / (height); pen.Color = cmap.GetColor(fraction); gfx.DrawLine(pen, 0, height - y - 1, width - 1, height - y - 1); } } else { for (int x = 0; x < width; x++) { double fraction = (double)x / width; pen.Color = cmap.GetColor(fraction); gfx.DrawLine(pen, x, 0, x, height - 1); } } } return(bmp); }
public void CreateUnsafe_AvailableName_ColormapNameMatchrequested(string Name) { var factory = new ColormapFactory(); ScottPlot.Drawing.Colormap result = factory.CreateUnsafe(Name); Assert.AreEqual(Name, result.Name); }
/// <summary> /// Add a colorbar to display a colormap beside the data area /// </summary> public Colorbar AddColorbar(Drawing.Colormap colormap = null, int space = 100) { var cb = new Colorbar(colormap); Add(cb); YAxis2.SetSizeLimit(min: space); return(cb); }
public void CreateUnsafe_NotAvailableName_Throws(string Name) { var factory = new ColormapFactory(); Assert.Throws <ArgumentOutOfRangeException>(() => { ScottPlot.Drawing.Colormap result = factory.CreateUnsafe(Name); }); }
public static Color[] GetColors(double[] intensities, Colormap colorMap) { Color[] colors = new Color[intensities.Length]; for (int i = 0; i < intensities.Length; i++) { byte pixelIntensity = (byte)Math.Max(Math.Min(intensities[i] * 255, 255), 0); var(r, g, b) = colorMap.GetRGB(pixelIntensity); colors[i] = Color.FromArgb(255, r, g, b); } return(colors); }
public static int[] GetRGBAs(double[] intensities, Colormap colorMap, double minimumIntensity = 0) { int[] rgbas = new int[intensities.Length]; for (int i = 0; i < intensities.Length; i++) { byte pixelIntensity = (byte)Math.Max(Math.Min(intensities[i] * 255, 255), 0); var(r, g, b) = colorMap.GetRGB(pixelIntensity); byte alpha = pixelIntensity < minimumIntensity ? (byte)0 : (byte)255; byte[] argb = { b, g, r, alpha }; rgbas[i] = BitConverter.ToInt32(argb, 0); } return(rgbas); }
/// <summary> /// Add a heatmap to the plot /// </summary> public Heatmap AddHeatmap(double[,] intensities, Drawing.Colormap colormap = null, bool lockScales = true) { if (lockScales) { AxisScaleLock(true); } var plottable = new Heatmap(); plottable.Update(intensities, colormap); Add(plottable); return(plottable); }
/// <summary> /// Add a colorbar to display a colormap beside the data area /// </summary> /// <param name="colormap">Colormap to display in this colorbar</param> /// <param name="space">The size of the right axis will be set to this number of pixels to make room for the colorbar</param> /// <param name="rightSide">If false the colorbar will be displayed on the left edge of the plot.</param> /// <returns>the colorbar that was just created</returns> public Colorbar AddColorbar(Drawing.Colormap colormap = null, int space = 100, bool rightSide = true) { var cb = new Colorbar(colormap); if (rightSide) { cb.Edge = Renderable.Edge.Right; YAxis2.SetSizeLimit(min: space); } else { cb.Edge = Renderable.Edge.Left; YAxis.SetSizeLimit(min: space); } Add(cb); return(cb); }
public VectorField PlotVectorField( Statistics.Vector2[,] vectors, double[] xs, double[] ys, string label = null, Color?color = null, Drawing.Colormap colormap = null, double scaleFactor = 1 ) { var vectorField = new VectorField(vectors, xs, ys, colormap, scaleFactor, color ?? settings.GetNextColor()) { label = label }; Add(vectorField); return(vectorField); }
/// <summary> /// Add a heatmap to the plot automatically-sized so each cell is 1x1. /// </summary> /// <param name="intensities">2D array of intensities. /// WARNING: Rendering artifacts may appear for arrays larger than Bitmap can support (~10M total values).</param> /// <param name="colormap"></param> /// <param name="lockScales">If true, AxisScaleLock() will be called to ensure heatmap cells will be square.</param> /// <returns> /// Returns the heatmap that was added to the plot. /// Act on its public fields and methods to customize it or update its data. /// </returns> public Heatmap AddHeatmap(double[,] intensities, Drawing.Colormap colormap = null, bool?lockScales = null) { var plottable = new Heatmap(); plottable.Update(intensities, colormap); Add(plottable); if (lockScales.HasValue && lockScales.Value == true) { AxisScaleLock(true); } if (lockScales is null && plottable.IsDefaultSizeAndLocation) { AxisScaleLock(true); } return(plottable); }
public PlottableHeatmap PlotHeatmap( double[,] intensities, Drawing.Colormap colormap = null, string label = null, double[] axisOffsets = null, double[] axisMultipliers = null, double?scaleMin = null, double?scaleMax = null, double?transparencyThreshold = null, Bitmap backgroundImage = null, bool displayImageAbove = false, bool drawAxisLabels = true ) { if (colormap == null) { colormap = Drawing.Colormap.Viridis; } if (axisOffsets == null) { axisOffsets = new double[] { 0, 0 } } ; if (axisMultipliers == null) { axisMultipliers = new double[] { 1, 1 } } ; PlottableHeatmap heatmap = new PlottableHeatmap(intensities, colormap, label, axisOffsets, axisMultipliers, scaleMin, scaleMax, transparencyThreshold, backgroundImage, displayImageAbove, drawAxisLabels); Add(heatmap); MatchAxis(this); Ticks(false, false); Layout(y2LabelWidth: 180); return(heatmap); } } }
public PlottableVectorField PlotVectorField( Statistics.Vector2[,] vectors, double[] xs, double[] ys, string label = null, Color?color = null, Drawing.Colormap colormap = null, double scaleFactor = 1 ) { if (!color.HasValue) { color = settings.GetNextColor(); } var vectorField = new PlottableVectorField(vectors, xs, ys, label, color.Value, colormap, scaleFactor); Add(vectorField); return(vectorField); }
public PlottableHeatmap PlotHeatmap( double[,] intensities, Drawing.Colormap colormap = null, string label = null, double[] axisOffsets = null, double[] axisMultipliers = null, double?scaleMin = null, double?scaleMax = null, double?transparencyThreshold = null, Bitmap backgroundImage = null, bool displayImageAbove = false, bool drawAxisLabels = true ) { PlottableHeatmap heatmap = new PlottableHeatmap() { label = label, AxisOffsets = axisOffsets ?? new double[] { 0, 0 }, AxisMultipliers = axisMultipliers ?? new double[] { 1, 1 }, ScaleMin = scaleMin, ScaleMax = scaleMax, TransparencyThreshold = transparencyThreshold, BackgroundImage = backgroundImage, DisplayImageAbove = displayImageAbove, ShowAxisLabels = drawAxisLabels, Colormap = colormap ?? Drawing.Colormap.Viridis }; heatmap.UpdateData(intensities); Add(heatmap); MatchAxis(this); Ticks(false, false); Layout(y2LabelWidth: 180); return(heatmap); }
public void Test_Colormap_GetColormapByName() { ScottPlot.Drawing.Colormap cmap = ScottPlot.Drawing.Colormap.GetColormapByName("Inferno"); Assert.IsNotNull(cmap); Assert.AreEqual("Inferno", cmap.Name); }
[EditorBrowsable(EditorBrowsableState.Never)] // Prevents suggestions in Intellisense for downstream users. Still shows up while editing this assembly. public CoordinatedHeatmap AddHeatMapCoordinated(double[,] intensities, double?xMin = null, double?xMax = null, double?yMin = null, double?yMax = null, Drawing.Colormap colormap = null) { return(AddHeatmapCoordinated(intensities, xMin, xMax, yMin, yMax, colormap)); }
public void Create_AvailableName_NotThrows(string Name) { var factory = new ColormapFactory(); ScottPlot.Drawing.Colormap result = factory.Create(Name); }
/// <summary> /// Add heatmap to the plot stretched to fit the given dimensions. /// Unlike the regular heatmap which gives each cell a size of 1x1 and starts at the axis origin, /// this heatmap stretches the array so that it covers the defined X and Y spans. /// </summary> /// <param name="intensities">2D array of intensities. /// WARNING: Rendering artifacts may appear for arrays larger than Bitmap can support (~10M total values).</param> /// <param name="xMin">position of the left edge of the far left column</param> /// <param name="xMax">position of the left edge of the far right column</param> /// <param name="yMin">position of the upper edge of the bottom row</param> /// <param name="yMax">position of the upper edge of the top row</param> /// <param name="colormap"></param> /// <returns> /// Returns the heatmap that was added to the plot. /// Act on its public fields and methods to customize it or update its data. /// </returns> 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); }