public void Test_PlottableBar2_SingleSeries() { double[,] values = new double[, ] { { 7, 12, 40, 40, 100, 125, 172, 550, 560, 600, 2496, 2789 } }; string[] rowLabels = new string[] { null }; string[] colLabels = new string[] { "ant", "bird", "mouse", "human", "cat", "dog", "frog", "lion", "elephant", "horse", "shark", "hippo" }; Assert.AreEqual(values.GetLength(0), rowLabels.Length); Assert.AreEqual(values.GetLength(1), colLabels.Length); var plt = new ScottPlot.Plot(400, 300); // create and add an experimental plottable (not in the ScottPlot namespace) var pltBar = new PlottableBar2(rowLabels, colLabels, values); plt.Add(pltBar); plt.Title("Body-to-Brain Mass Ratio"); plt.XTicks(colLabels); plt.Axis(-1, colLabels.Length, 0, null); plt.Grid(enableVertical: false); // customize ticks to display better at high density plt.Ticks(useMultiplierNotation: false); plt.Ticks(xTickRotation: 45); plt.Layout(xLabelHeight: 40); TestTools.SaveFig(plt); }
public void Test_PlottableBar2_MultiSeries() { double[,] values = new double[, ] { { 15, 22, 45, 17 }, { 37, 21, 29, 13 } }; string[] rowLabels = new string[] { "men", "women" }; string[] colLabels = new string[] { "always", "regularly", "sometimes", "never" }; Assert.AreEqual(values.GetLength(0), rowLabels.Length); Assert.AreEqual(values.GetLength(1), colLabels.Length); var plt = new ScottPlot.Plot(400, 300); // create and add an experimental plottable (not in the ScottPlot namespace) var pltBar = new PlottableBar2(rowLabels, colLabels, values); plt.Add(pltBar); plt.Title("How often do you read reviews?"); plt.XTicks(colLabels); plt.Ticks(useMultiplierNotation: false); plt.Axis(-1, colLabels.Length, 0, null); plt.Grid(enableVertical: false); TestTools.SaveFig(plt); }
public void AxisVSpan_ExtremeZoomIn_FullScreenIsSpanColor() { var plt = new ScottPlot.Plot(); var axSpan = new VSpan() { Y1 = 1, Y2 = 10, Color = System.Drawing.Color.Green }; plt.Add(axSpan); // Initial zoom to fill full plot with span color plt.AxisZoom(1, 10); var smallZoomBmp = TestTools.GetLowQualityBitmap(plt); var smallZoom = new MeanPixel(smallZoomBmp); // Extreme zoom to prove that full plot filled with span Color plt.AxisZoom(1, 10_000_000); var extremeZoomBmp = TestTools.GetLowQualityBitmap(plt); var extremeZoom = new MeanPixel(extremeZoomBmp); // Compare mean pixel with delta, because different ticks // Y Ticks has more affect on mean pixel Assert.AreEqual(smallZoom.RGB, extremeZoom.RGB, 20); }
public void Test_AxisSpan_ChangesPosition() { var plt = new ScottPlot.Plot(); // start with default settings var axSpan = new HSpan() { X1 = 1.23, X2 = 2.34 }; plt.Add(axSpan); var bmp1 = TestTools.GetLowQualityBitmap(plt); // change the plottable axSpan.X2 += 1; 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); Console.WriteLine($"Before: {before}"); Console.WriteLine($"After: {after}"); Assert.That(after.IsDarkerThan(before)); }
public void Test_ManualPolygon_Render() { Random rand = new Random(0); var plt = new ScottPlot.Plot(); for (int i = 0; i < 5; i++) { var color = plt.GetSettings(false).GetNextColor(); var plottable = new ScottPlot.Plottable.Polygon( xs: ScottPlot.DataGen.Random(rand, 3, 100), ys: ScottPlot.DataGen.Random(rand, 3, 100)) { Label = $"polygon {i + 1}", LineWidth = 2, LineColor = color, Fill = true, FillColor = color, }; plt.Add(plottable); } plt.Title("Polygon Example"); plt.Legend(location: ScottPlot.Alignment.LowerLeft); TestTools.SaveFig(plt); }
public void Test_ManualPolygon_Render() { Random rand = new Random(0); var plt = new ScottPlot.Plot(); for (int i = 0; i < 5; i++) { var color = plt.GetSettings(false).GetNextColor(); var plottable = new ScottPlot.PlottablePolygon( xs: ScottPlot.DataGen.Random(rand, 3, 100), ys: ScottPlot.DataGen.Random(rand, 3, 100), label: $"polygon {i + 1}", lineWidth: 2, lineColor: color, fill: true, fillColor: color, fillAlpha: .5 ); plt.Add(plottable); } plt.Title("Polygon Example"); plt.Legend(location: ScottPlot.legendLocation.lowerLeft); TestTools.SaveFig(plt); }
public void Test_Scatter_Mutable() { var plt = new ScottPlot.Plot(); var scatter = new ScottPlot.Plottable.ScatterPlotList(); plt.Add(scatter); TestTools.SaveFig(plt, "no_points"); scatter.Add(1, 1); plt.AxisAuto(); TestTools.SaveFig(plt, "one_point"); scatter.Add(2, 2); plt.AxisAuto(); TestTools.SaveFig(plt, "two_points"); scatter.AddRange(new double[] { 3, 4, 5 }, new double[] { 1, 6, 3 }); plt.AxisAuto(); TestTools.SaveFig(plt, "many_points"); }
//[Test] public void Test_DocPlottables_CreateAndAdd() { double[] xs = { 1, 2, 3, 4, 5 }; double[] ys = { 1, 4, 9, 16, 25 }; var plt = new ScottPlot.Plot(400, 300); var scatter = new ScottPlot.Plottable.ScatterPlot(xs, ys) { Color = Color.Green, LineWidth = 2 }; plt.Add(scatter); TestTools.SaveFig(plt); string thisHash = ScottPlot.Tools.BitmapHash(plt.Render()); createHash ??= thisHash; Assert.AreEqual(createHash, thisHash); }
public void Test_Annotation_Plottable() { var plottable = new ScottPlot.PlottableAnnotation( xPixel: 50, yPixel: 10, label: "seems like it works", fontSize: 16, fontName: "Arial Narrow", fontColor: Color.Magenta, fill: true, fillColor: Color.Green, lineWidth: 2, lineColor: Color.Blue, shadow: true ); var plt = new ScottPlot.Plot(400, 300); plt.Add(plottable); TestTools.SaveFig(plt); }
public static void Main(string[] args) { const int maxDepth = 7; const int minDepth = 1; const int popSize = 250; const uint maxGenerations = 250; const uint elitism = 5; const uint tournamentSize = 50; const float growTerminalChance = .5f; const float pCrossover = .3f; const float pMutation = .5f; string[] terminals = new string[] { "1", "0.5" }; string[] functions = new string[] { "add", "mul", "sub", "div", "pow" }; List <Tuple <List <float>, float> > Data = new List <Tuple <List <float>, float> >(); using (StreamReader sr = new StreamReader("concrete.txt")) { string line; while ((line = sr.ReadLine()) != null) { var strData = line.Replace("\t", "").Split(' ', StringSplitOptions.RemoveEmptyEntries); List <float> inputs = new List <float>(); for (int i = 0; i < strData.Length - 1; i++) { terminals = terminals.Append("x" + i).ToArray(); inputs.Add(float.Parse(strData[i], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture)); } Data.Add(new Tuple <List <float>, float>(inputs, (float.Parse(strData[strData.Length - 1], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture)))); } } var plt = new ScottPlot.Plot(); for (int i = 0; i < Data.Count; i++) { for (int j = 0; j < Data[0].Item1.Count; j++) { plt.PlotPoint(Data[i].Item1[j], Data[i].Item2, Color.Red, label: "Original Data"); } } Population <string> pop = new Population <string>(popSize, tournamentSize, pCrossover, pMutation, elitism, maxDepth, minDepth, functions, terminals, growTerminalChance); pop.Init(); pop.Individuals = CalculateFitness(Data, pop.Individuals, terminals); for (int i = 0; i < maxGenerations; i++) { pop.Evolve(); pop.Individuals = CalculateFitness(Data, pop.Individuals, terminals); if (pop.Individuals.Any(i => i.Fitness <= 0)) { Console.WriteLine("Solution reached in generation: " + i); break; } } Console.WriteLine("Fitness: " + pop.Individuals[0].Fitness); pop.Individuals[0].PrintTree(); var op = Evaluate(pop.Individuals[0], terminals); for (int i = 0; i < Data.Count; i++) { for (int j = 0; j < Data[0].Item1.Count; j++) { plt.Add(plt.PlotPoint(Data[i].Item1[j], op.Compute(Data[i].Item1.Select(d => (double)d).ToArray()), Color.Blue, label: "Estimate")); } } plt.SaveFig("output.png"); }