public void Test_Arrow_PixelOffset() { var plt = new ScottPlot.Plot(400, 300); plt.AddPoint(1, 2, size: 20); plt.AddPoint(3, 4, size: 20); // initial plot var arrow = plt.AddArrow(1, 2, 3, 4); plt.Margins(.5, .5); var bmp1 = TestTools.GetLowQualityBitmap(plt); // adjust something arrow.PixelOffsetX = 20; arrow.PixelOffsetY = -20; var bmp2 = TestTools.GetLowQualityBitmap(plt); // measure what changed //TestTools.SaveFig(bmp1, "1"); //TestTools.SaveFig(bmp2, "2"); var before = new MeanPixel(bmp1); var after = new MeanPixel(bmp2); Assert.That(after.IsDifferentThan(before)); }
public void Test_AxisSpan_AutoAxisRespected(bool ignore) { // plot with small data in the center var plt = new ScottPlot.Plot(); plt.AddPoint(-10, -10); plt.AddPoint(10, 10); plt.AxisAuto(); var limits1 = plt.GetAxisLimits(); // large data var span1 = plt.AddVerticalSpan(-999, 999); var span2 = plt.AddHorizontalSpan(-999, 999); span1.IgnoreAxisAuto = ignore; span2.IgnoreAxisAuto = ignore; plt.AxisAuto(); var limits2 = plt.GetAxisLimits(); if (ignore) { Assert.AreEqual(limits1, limits2); } else { Assert.AreNotEqual(limits1, limits2); } }
public void Test_Text_Alignment() { ScottPlot.Alignment[] alignments = (ScottPlot.Alignment[])Enum.GetValues(typeof(ScottPlot.Alignment)); var plt = new ScottPlot.Plot(400, 300); for (int i = 0; i < alignments.Length; i++) { double frac = (double)i / alignments.Length; double x = Math.Sin(frac * Math.PI * 2); double y = Math.Cos(frac * Math.PI * 2); var txt = plt.AddText(alignments[i].ToString(), x, y); txt.Alignment = alignments[i]; txt.Font.Color = System.Drawing.Color.Black;; txt.BackgroundColor = System.Drawing.Color.LightSteelBlue; txt.BackgroundFill = true; txt.Rotation = 5; txt.BorderSize = 2; txt.BorderColor = System.Drawing.Color.Navy; plt.AddPoint(x, y, System.Drawing.Color.Black); } plt.Frameless(); plt.Margins(.5, .2); TestTools.SaveFig(plt); }
public void Test_AxisAuto_Works() { var plt = new ScottPlot.Plot(400, 300); plt.AddPoint(-5, -5); plt.AddPoint(5, 5); // set limits too small plt.SetAxisLimits(-1, 1, -1, 1); var limits1 = plt.GetAxisLimits(); // autoAxis should make them bigger plt.AxisAuto(); var limits2 = plt.GetAxisLimits(); Assert.Less(limits2.XMin, limits1.XMin); Assert.Greater(limits2.XMax, limits1.XMax); Assert.Less(limits2.YMin, limits1.YMin); Assert.Greater(limits2.YMax, limits1.YMax); }
public void Test_TextRotationAlignment_LowerRight() { var plt = new ScottPlot.Plot(400, 300); int[] rotations = { 0, 90, -90, 180 }; for (int i = 0; i < rotations.Length; i++) { string label = $"Rot{rotations[i]}"; double x = i / 2; double y = i % 2; var txt = plt.AddText(label, x, y); txt.Rotation = rotations[i]; txt.Alignment = ScottPlot.Alignment.LowerRight; txt.Font.Size = 24; plt.AddPoint(x, y, Color.Red, size: 5); } plt.Title("TextAlignment.lowerRight"); plt.AxisAuto(.5, .5); TestTools.SaveFig(plt); }
public void Test_TextRotationAlignment_LowerRight() { var plt = new ScottPlot.Plot(400, 300); int[] rotations = { 0, 90, -90, 180 }; for (int i = 0; i < rotations.Length; i++) { string label = $"Rot{rotations[i]}"; double x = i / 2; double y = i % 2; plt.PlotText(label, x, y, Color.Black, rotation: rotations[i], alignment: ScottPlot.Alignment.LowerRight, fontSize: 24, frame: true, frameColor: Color.LightGray); plt.AddPoint(x, y, Color.Red, size: 5); } plt.Title("TextAlignment.lowerRight"); plt.AxisAuto(.5, .5); TestTools.SaveFig(plt); }
public void Test_ImageRotationAlignment_LowerRight() { var plt = new ScottPlot.Plot(400, 300); System.Drawing.Bitmap image = ScottPlot.DataGen.SampleImage(); int[] rotations = { 0, 90, -90, 180 }; for (int i = 0; i < rotations.Length; i++) { double x = i / 2; double y = i % 2; var img = plt.AddImage(image, x, y); img.Rotation = rotations[i]; img.Alignment = ScottPlot.Alignment.LowerRight; img.BorderColor = Color.LightGray; img.BorderSize = 5; plt.AddPoint(x, y, Color.Red, size: 5); } plt.Title("ImageRotationAlignment.lowerRight"); plt.AxisAuto(.5, .5); TestTools.SaveFig(plt); }
public void Test_ImageRotationAlignment_LowerRight() { var plt = new ScottPlot.Plot(400, 300); System.Drawing.Bitmap image = ScottPlot.DataGen.SampleImage(); int[] rotations = { 0, 90, -90, 180 }; for (int i = 0; i < rotations.Length; i++) { double x = i / 2; double y = i % 2; plt.PlotBitmap(bitmap: image, x, y, rotation: rotations[i], alignment: ScottPlot.Alignment.LowerRight, frameColor: Color.LightGray, frameSize: 5); plt.AddPoint(x, y, Color.Red, size: 5); } plt.Title("TextAlignment.lowerRight"); plt.AxisAuto(.5, .5); TestTools.SaveFig(plt); }
public void Test_ImageScale() { var plt = new ScottPlot.Plot(800, 600); System.Drawing.Bitmap image = ScottPlot.DataGen.SampleImage(); float[] scales = { 0.2f, 0.5f, 1f, 1.5f }; for (int i = 0; i < scales.Length; i++) { double x = i / 2; double y = i % 2; var img = plt.AddImage(image, x, y); img.Scale = scales[i]; img.Rotation = 30; img.Alignment = ScottPlot.Alignment.LowerRight; img.BorderColor = Color.LightGray; img.BorderSize = 5; plt.AddPoint(x, y, Color.Red, size: 5); } plt.Title("ImageScale"); plt.AxisAuto(.5, .5); TestTools.SaveFig(plt); }
public void Test_Mel_Graph() { int specPoints = 4096; double maxFreq = 50_000; double maxMel = 2595 * Math.Log10(1 + maxFreq / 700); Random rand = new Random(1); double[] freq = ScottPlot.DataGen.Consecutive(specPoints, maxFreq / specPoints); double[] power = ScottPlot.DataGen.RandomWalk(rand, specPoints, .02, .5); var plt1 = new ScottPlot.Plot(800, 300); plt1.AddScatter(freq, power, markerSize: 0); int filterSize = 25; // generate scales double[] pointsLinear = new double[filterSize + 1]; double[] pointsMel = new double[filterSize + 1]; for (int i = 0; i < filterSize + 1; i++) { double thisFreq = maxFreq * i / filterSize; double thisMel = maxMel * i / filterSize; pointsLinear[i] = thisFreq; pointsMel[i] = 700 * (Math.Pow(10, thisMel / 2595d) - 1); } // draw rectangles double[] binStartFreqs = pointsMel; for (int binIndex = 0; binIndex < binStartFreqs.Length - 2; binIndex++) { double freqLow = binStartFreqs[binIndex]; double freqCenter = binStartFreqs[binIndex + 1]; double freqHigh = binStartFreqs[binIndex + 2]; var sctr = plt1.AddScatter( xs: new double[] { freqLow, freqCenter, freqHigh }, ys: new double[] { 0, 1, 0 }, markerSize: 0, lineWidth: 2); int indexLow = (int)(specPoints * freqLow / maxFreq); int indexHigh = (int)(specPoints * freqHigh / maxFreq); int indexSpan = indexHigh - indexLow; Console.WriteLine($"bin {binIndex}: [{freqLow} Hz - {freqHigh} Hz] = [{indexLow}:{indexHigh}]"); double binValue = 0; double binScaleSum = 0; for (int i = 0; i < indexSpan; i++) { double frac = (double)i / indexSpan; frac = (frac < .5) ? frac * 2 : 1 - frac; binScaleSum += frac; binValue += power[indexLow + i] * frac; } binValue /= binScaleSum; plt1.AddPoint(freqCenter, binValue, sctr.Color, 10); } plt1.SaveFig("mel1.png"); }