public void ExecuteRecipe(Plot plt) { double[] xs = DataGen.Range(0, 5, .1); plt.AddScatter(xs, DataGen.Sin(xs)); plt.AddScatter(xs, DataGen.Cos(xs)); // default placement is upper left plt.AddAnnotation("Top Left", 10, 10); // negative coordinates can be used to place text along different edges plt.AddAnnotation("Lower Left", 10, -10); plt.AddAnnotation("Top Right", -10, 10); plt.AddAnnotation("Lower Right", -10, -10); // Additional customizations are available var fancy = plt.AddAnnotation("Fancy Annotation", 10, 40); fancy.FontSize = 24; fancy.FontName = "Impact"; fancy.FontColor = Color.Red; fancy.Shadow = false; fancy.BackgroundColor = Color.FromArgb(25, Color.Blue); fancy.BorderWidth = 2; fancy.BorderColor = Color.Magenta; }
public graphingWindow(double[] Loads, string name, double loadMax) { graphName = name; loads = Loads; this.xs = DataGen.Range(loads.Length); InitializeComponent(); double[] xs = DataGen.Range(loads.Count()); var newLoads = new double[xs.Length]; for (int i = 0; i < loads.Length; i++) { if (loads[i] > loadMax) { newLoads[i] = loadMax; } else { newLoads[i] = loads[i]; } } graphPlotForm.plt.PlotScatter(xs, loads); graphPlotForm.plt.PlotScatter(xs, newLoads); graphPlotForm.plt.Title(name); graphPlotForm.plt.XLabel("Hours"); graphPlotForm.plt.YLabel("Loads (kW)"); //graphPlotForm.plt.PlotFill(xs, loads, lineColor: Color.AliceBlue, fillColor: Color.Beige); graphPlotForm.Render(); }
public void Render(Plot plt) { double[] xs = DataGen.Range(-1.5, 1.5, .25); double[] ys = DataGen.Range(-1.5, 1.5, .25); Vector2[,] vectors = new Vector2[xs.Length, ys.Length]; for (int i = 0; i < xs.Length; i++) { for (int j = 0; j < ys.Length; j++) { double x = xs[i]; double y = ys[j]; var e = Math.Exp(-x * x - y * y); var dx = (1 - 2 * x * x) * e; var dy = -2 * x * y * e; vectors[i, j] = new Vector2(dx, dy); } } var field = plt.PlotVectorField(vectors, xs, ys, scaleFactor: 0.25); field.Centered = false; field.FancyTip = true; }
public static Plot CreateAdvancedStatisticsPlot() { var plt = new ScottPlot.Plot(600, 400); // create some sample data to represent test scores Random rand = new Random(0); double[] scores = DataGen.RandomNormal(rand, 250, 85, 5); // create a Population object from the data var pop = new ScottPlot.Statistics.Population(scores); // display the original values scattered vertically double[] ys = DataGen.RandomNormal(rand, pop.values.Length, stdDev: .15); plt.PlotScatter(pop.values, ys, markerSize: 10, markerShape: MarkerShape.openCircle, lineWidth: 0); // display the bell curve for this distribution double[] curveXs = DataGen.Range(pop.minus3stDev, pop.plus3stDev, .1); double[] curveYs = pop.GetDistribution(curveXs); plt.PlotScatter(curveXs, curveYs, markerSize: 0, lineWidth: 2); // improve the style of the plot plt.Title($"Test Scores (mean: {pop.mean:0.00} +/- {pop.stDev:0.00}, n={pop.n})"); plt.XLabel("Score"); plt.Grid(lineStyle: LineStyle.Dot); return(plt); //plt.SaveFig("Advanced_Statistics_Population.png"); }
/// <summary> /// Return log-distributed points between the min/max values /// </summary> /// <param name="count">number of divisions</param> /// <param name="min">lowest value</param> /// <param name="max">highest value</param> /// <param name="inclusive">if true, returned values will contain the min/max values themselves</param> /// <returns></returns> public static double[] GetLogDistributedPoints(int count, double min, double max, bool inclusive) { double range = max - min; var values = DataGen.Range(1, 10, 10.0 / count) .Select(x => Math.Log10(x)) .Select(x => x * range + min); return(inclusive ? values.ToArray() : values.Skip(1).Take(count - 2).ToArray()); }
public DebounceView() { InitializeComponent(); PlotEventPasserThing.ChartDataUpdated += UpdateChart; SignalView.Configuration.LockVerticalAxis = true; SignalView.Configuration.Quality = ScottPlot.Control.QualityMode.High; SignalView.Plot.Frame(false); SignalView.Plot.SetViewLimits(0, 5000); SignalView.Plot.Layout(padding: 0); double[] xs = DataGen.Range(0, 5000, 1); // left button (raw) line double[] leftButtonData = DataGen.Random(new Random(), pointCount: 5000, multiplier: 0, offset: 1.25); var leftSignalPlot = SignalView.Plot.AddSignal(leftButtonData); leftSignalPlot.MarkerSize = 4; leftSignalPlot.Color = System.Drawing.Color.FromArgb(140, 103, 58, 183); // left button (debounced) var leftDebouncedSignalPlot = SignalView.Plot.AddSignal(leftButtonData); leftDebouncedSignalPlot.MarkerSize = 4; leftDebouncedSignalPlot.LineWidth = 3; leftDebouncedSignalPlot.Color = System.Drawing.Color.FromArgb(103, 58, 183); // right button (raw) line double[] rightButtonData = DataGen.Random(new Random(), pointCount: 5000, multiplier: 0, offset: 0); var rightSignalPlot = SignalView.Plot.AddSignal(rightButtonData); rightSignalPlot.MarkerSize = 4; rightSignalPlot.Color = System.Drawing.Color.FromArgb(140, 255, 109, 0); // right button (debounced) var rightDebouncedSignalPlot = SignalView.Plot.AddSignal(rightButtonData); rightDebouncedSignalPlot.MarkerSize = 4; rightDebouncedSignalPlot.LineWidth = 3; rightDebouncedSignalPlot.Color = System.Drawing.Color.FromArgb(255, 109, 0); // X Axis SignalView.Plot.XAxis.MinimumTickSpacing(1); SignalView.Plot.XAxis.Label("Milliseconds"); // Y Axis SignalView.Plot.YAxis.Grid(false); double[] ys = new double[] { 0, 1, 1.25, 2.25 }; string[] ylabels = new string[] { "released", "pressed", "released", "pressed" }; SignalView.Plot.YTicks(ys, ylabels); SignalView.Plot.SetAxisLimitsY(-0.1, 2.25 + 0.1); }
public void Render(Plot plt) { double[] xs = DataGen.Range(0, 10, .1, true); double[] sin = DataGen.Sin(xs); double[] cos = DataGen.Cos(xs); plt.PlotFill(xs, sin, xs, cos, fillAlpha: .5); plt.PlotScatter(xs, sin, Color.Black); plt.PlotScatter(xs, cos, Color.Black); plt.AxisAuto(0); }
public void Render(Plot plt) { double[] xs = DataGen.Range(0, 10, .1, true); double[] sin = DataGen.Sin(xs); double[] cos = DataGen.Cos(xs); plt.PlotFill(xs, sin, "sin", lineWidth: 2, fillAlpha: .5); plt.PlotFill(xs, cos, "cos", lineWidth: 2, fillAlpha: .5); plt.PlotHLine(0, color: Color.Black); plt.AxisAuto(0); plt.Legend(location: legendLocation.lowerLeft); }
public void ExecuteRecipe(Plot plt) { // create sample data double[] xs = DataGen.Range(0, 10, .1, true); double[] ys1 = DataGen.Sin(xs); double[] ys2 = DataGen.Cos(xs); // add filled polygons plt.AddFill(xs, ys1); plt.AddFill(xs, ys2, baseline: -.25); // tighten the axis limits so we don't see lines on the edges plt.SetAxisLimits(xMin: 0, xMax: 10); }
public void Test_TickAlignment_SnapEdgePixel() { Random rand = new Random(0); double[] xs = DataGen.Range(0, 10, .1, true); double[] ys = DataGen.RandomWalk(rand, xs.Length, .5); var plt = new ScottPlot.Plot(320, 240); plt.AddScatter(xs, ys, markerSize: 0); plt.AddScatter(ys, xs, markerSize: 0); plt.AxisAuto(0, 0); TestTools.SaveFig(plt); }
public void Render(Plot plt) { double[] xs = DataGen.Range(0, 5, .1); plt.PlotScatter(xs, DataGen.Sin(xs)); plt.PlotScatter(xs, DataGen.Cos(xs)); // negative coordinates snap text to the lower or right edges plt.PlotAnnotation("Top Left", 10, 10); plt.PlotAnnotation("Lower Left", 10, -10); plt.PlotAnnotation("Top Right", -10, 10); plt.PlotAnnotation("Lower Right", -10, -10); // arguments allow customization of style plt.PlotAnnotation("Fancy Annotation", 10, 40, fontSize: 24, fontName: "Impact", fontColor: Color.Red, shadow: true, fill: true, fillColor: Color.White, fillAlpha: 1, lineWidth: 2); }
public void ExecuteRecipe(Plot plt) { // create sample data double[] xs = DataGen.Range(0, 10, .1, true); double[] ys1 = DataGen.Sin(xs); double[] ys2 = DataGen.Cos(xs); // add a polygon to fill the region between the two curves plt.AddFill(xs, ys1, xs, ys2); // add two scatter plots the traditional way plt.AddScatter(xs, ys1, color: Color.Black); plt.AddScatter(xs, ys2, color: Color.Black); // tighten the axis limits so we don't see lines on the edges plt.SetAxisLimits(xMin: 0, xMax: 10); }
public void Test_Population_CurveSideways() { Random rand = new Random(0); var ages = new ScottPlot.Statistics.Population(rand, 44, 78, 2); double[] curveXs = DataGen.Range(ages.minus3stDev, ages.plus3stDev, .1); double[] curveYs = ages.GetDistribution(curveXs); var plt = new ScottPlot.Plot(400, 300); plt.PlotScatter(DataGen.Random(rand, ages.values.Length), ages.values, markerSize: 10, markerShape: MarkerShape.openCircle, lineWidth: 0); plt.PlotScatter(curveYs, curveXs, markerSize: 0); plt.Grid(lineStyle: LineStyle.Dot); TestTools.SaveFig(plt); }
public void Render(Plot plt) { double[] xs = DataGen.Range(0, 10, .1, true); double[] sin = DataGen.Sin(xs); double[] cos = DataGen.Cos(xs); var sinPlot = plt.PlotFill(xs, sin, "sin", lineWidth: 2, fillAlpha: .5); var cosPlot = plt.PlotFill(xs, cos, "cos", lineWidth: 2, fillAlpha: .5); sinPlot.HatchStyle = Drawing.HatchStyle.StripedDownwardDiagonal; sinPlot.HatchColor = Color.Black; cosPlot.HatchStyle = Drawing.HatchStyle.StripedUpwardDiagonal; cosPlot.HatchColor = Color.White; plt.PlotHLine(0, color: Color.Black); plt.AxisAuto(0); plt.Legend(location: Alignment.UpperRight); }
public void ExecuteRecipe(Plot plt) { double[] xPositions = DataGen.Range(0, 10); double[] yPositions = DataGen.Range(0, 10); Vector2[,] vectors = new Vector2[xPositions.Length, yPositions.Length]; for (int x = 0; x < xPositions.Length; x++) { for (int y = 0; y < yPositions.Length; y++) { vectors[x, y] = new Vector2( x: Math.Sin(xPositions[x]), y: Math.Sin(yPositions[y])); } } plt.AddVectorField(vectors, xPositions, yPositions); }
public AxisLimits GetAxisLimits() { double max = double.NegativeInfinity; double min = double.PositiveInfinity; foreach (double x in DataGen.Range(-10, 10, .1)) { double?y = function(x); if (y != null) { max = Math.Max(max, y.Value); min = Math.Min(min, y.Value); } } // TODO: should X limits be null or NaN? return(new AxisLimits(-10, 10, min, max)); }
public static void Distribution(PlotDimensions dims, Bitmap bmp, bool lowQuality, Population pop, Random rand, double popLeft, double popWidth, Color color, Position position, LineStyle lineStyle) { // adjust edges to accomodate special positions if (position == Position.Hide) { return; } if (position == Position.Left || position == Position.Right) { popWidth /= 2; } if (position == Position.Right) { popLeft += popWidth; } // contract edges slightly to encourage padding between elements double edgePaddingFrac = 0.2; popLeft += popWidth * edgePaddingFrac; popWidth -= (popWidth * edgePaddingFrac) * 2; double[] ys = DataGen.Range(pop.minus3stDev, pop.plus3stDev, dims.UnitsPerPxY); if (ys.Length == 0) { return; } double[] ysFrac = pop.GetDistribution(ys, normalize: false); PointF[] points = new PointF[ys.Length]; for (int i = 0; i < ys.Length; i++) { float x = (float)dims.GetPixelX(popLeft + popWidth * ysFrac[i]); float y = (float)dims.GetPixelY(ys[i]); points[i] = new PointF(x, y); } using (Graphics gfx = GDI.Graphics(bmp, dims, lowQuality)) using (Pen pen = GDI.Pen(color, 1, lineStyle, true)) { gfx.DrawLines(pen, points); } }
public void ExecuteRecipe(Plot plt) { // create an interesting plot double[] xs = DataGen.Range(-5, 5, .5); double[] ys = DataGen.Range(-5, 5, .5); Vector2[,] vectors = new Vector2[xs.Length, ys.Length]; for (int i = 0; i < xs.Length; i++) { for (int j = 0; j < ys.Length; j++) { vectors[i, j] = new Vector2(ys[j], -15 * Math.Sin(xs[i])); } } plt.AddVectorField(vectors, xs, ys, colormap: Drawing.Colormap.Turbo); // use images as axis labels plt.XAxis.ImageLabel(new Bitmap("Images/theta.png")); plt.YAxis.ImageLabel(new Bitmap("Images/d_theta_dt.png")); }
public void ExecuteRecipe(Plot plt) { double[] xs = DataGen.Range(-5, 6); double[] ys = DataGen.Range(-5, 6); Vector2[,] vectors = new Vector2[xs.Length, ys.Length]; for (int i = 0; i < xs.Length; i++) { for (int j = 0; j < ys.Length; j++) { double slope = -xs[i]; double magnitude = Math.Abs(xs[i]); double angle = Math.Atan(slope); vectors[i, j] = new Vector2(Math.Cos(angle) * magnitude, Math.Sin(angle) * magnitude); } } plt.AddVectorField(vectors, xs, ys); }
public void ExecuteRecipe(Plot plt) { double[] xPositions = DataGen.Range(0, 10); double[] yPositions = DataGen.Range(0, 10); Vector2[,] vectors = new Vector2[xPositions.Length, yPositions.Length]; for (int x = 0; x < xPositions.Length; x++) { for (int y = 0; y < yPositions.Length; y++) { vectors[x, y] = new Vector2( x: Math.Sin(xPositions[x]), y: Math.Sin(yPositions[y])); } } var vf = plt.AddVectorField(vectors, xPositions, yPositions); vf.ScaledArrowheads = true; vf.Anchor = ArrowAnchor.Base; vf.MarkerSize = 3; }
public void ExecuteRecipe(Plot plt) { double[] xs = DataGen.Range(-1.5, 1.5, .25); double[] ys = DataGen.Range(-1.5, 1.5, .25); Vector2[,] vectors = new Vector2[xs.Length, ys.Length]; for (int i = 0; i < xs.Length; i++) { for (int j = 0; j < ys.Length; j++) { double x = xs[i]; double y = ys[j]; var e = Math.Exp(-x * x - y * y); var dx = (1 - 2 * x * x) * e; var dy = -2 * x * y * e; vectors[i, j] = new Vector2(dx, dy); } } plt.AddVectorField(vectors, xs, ys, scaleFactor: 0.3); }
public void ExecuteRecipe(Plot plt) { double[] xs = DataGen.Range(-5, 5, .5); double[] ys = DataGen.Range(-5, 5, .5); Vector2[,] vectors = new Vector2[xs.Length, ys.Length]; double r = 0.5; for (int i = 0; i < xs.Length; i++) { for (int j = 0; j < ys.Length; j++) { double x = ys[j]; double y = -9.81 / r * Math.Sin(xs[i]); vectors[i, j] = new Vector2(x, y); } } plt.AddVectorField(vectors, xs, ys, colormap: Drawing.Colormap.Turbo); plt.XLabel("θ"); plt.YLabel("dθ/dt"); }
public void Render(Plot plt) { double[] xs = DataGen.Range(-5, 5, .5); double[] ys = DataGen.Range(-5, 5, .5); Vector2[,] vectors = new Vector2[xs.Length, ys.Length]; double r = 0.5; for (int i = 0; i < xs.Length; i++) { for (int j = 0; j < ys.Length; j++) { double x = ys[j]; double y = -9.81 / r * Math.Sin(xs[i]); vectors[i, j] = new Vector2(x, y); } } plt.PlotVectorField(vectors, xs, ys, colormap: new Config.ColorMaps.Turbo()); plt.XLabel("θ"); plt.YLabel("dθ/dt"); }
//private static ScottPlot.Plot plt = new ScottPlot.Plot(600,400); public static double[] loads(ExcelBuilding building, string month, float dischargeThreshold = 40000f) { //ScottPlot.Plot plt = new Plot(); double[] loadValues = null; double[] xs; switch (month) { case "January": loadValues = building.JanuaryLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "February": loadValues = building.FebruaryLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "March": loadValues = building.MarchLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "April": loadValues = building.AprilLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "May": loadValues = building.MayLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "June": loadValues = building.JuneLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "July": loadValues = building.JulyLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "August": loadValues = building.AugustLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "September": loadValues = building.SeptemberLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "October": loadValues = building.OctoberLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "November": loadValues = building.NovemberLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; case "December": loadValues = building.DecemberLoads.ToArray(); xs = DataGen.Range(loadValues.Count()); //plt.PlotScatter(xs, loadValues); break; } return(loadValues); }