private void DisplayAxisInfo(ScottPlot.MultiPlot multiplot) { for (int i = 0; i < multiplot.subplots.Length; i += 1) { Console.WriteLine($"Subplot index {i} {multiplot.subplots[i].GetAxisLimits()}"); } }
public void Test_DefinedSpacing_NumericAxis() { int pointCount = 20; // create a series of day numbers double[] days = ScottPlot.DataGen.Consecutive(pointCount); // simulate data for each date double[] values = new double[pointCount]; Random rand = new Random(0); for (int i = 1; i < pointCount; i++) { values[i] = values[i - 1] + rand.NextDouble(); } var mplt = new ScottPlot.MultiPlot(1000, 400, 1, 2); var pltDefault = mplt.GetSubplot(0, 0); pltDefault.Title("Default xSpacing"); pltDefault.PlotScatter(days, values); var pltTest = mplt.GetSubplot(0, 1); pltTest.Title("xSpacing = 1 unit"); pltTest.PlotScatter(days, values); // force inter-tick distance on a numerical axis pltTest.Grid(xSpacing: 1); TestTools.SaveFig(mplt); }
public void Test_MultiPlot_MatchJustOneAxis() { ScottPlot.MultiPlot multiplot = SampleMultiPlot(); multiplot.subplots[1].MatchAxis(multiplot.subplots[3], horizontal: false); multiplot.subplots[1].MatchLayout(multiplot.subplots[3], horizontal: false); multiplot.subplots[1].Title("#1 (matched vertical to #3)"); multiplot.subplots[2].MatchAxis(multiplot.subplots[3], vertical: false); multiplot.subplots[2].MatchLayout(multiplot.subplots[3], vertical: false); multiplot.subplots[2].Title("#2 (matched hoizontal to #3)"); string name = System.Reflection.MethodBase.GetCurrentMethod().Name; string filePath = System.IO.Path.GetFullPath(name + ".png"); multiplot.SaveFig(filePath); Console.WriteLine($"Saved {filePath}"); DisplayAxisInfo(multiplot); var matchedVerticalLimits = multiplot.subplots[1].AxisLimits(); var matchedHorizontalLimits = multiplot.subplots[1].AxisLimits(); Assert.Greater(matchedVerticalLimits.XMax, matchedVerticalLimits.XMin); Assert.Greater(matchedVerticalLimits.YMax, matchedVerticalLimits.YMin); Assert.Greater(matchedHorizontalLimits.XMax, matchedHorizontalLimits.XMin); Assert.Greater(matchedHorizontalLimits.YMax, matchedHorizontalLimits.YMin); }
public void Test_MultiPlot_DefaultScales() { ScottPlot.MultiPlot multiplot = SampleMultiPlot(); string name = System.Reflection.MethodBase.GetCurrentMethod().Name; string filePath = System.IO.Path.GetFullPath(name + ".png"); multiplot.SaveFig(filePath); Console.WriteLine($"Saved {filePath}"); DisplayAxisInfo(multiplot); }
public void Test_DefinedSpacing_DateTimeAxis() { int pointCount = 20; // create a series of dates double[] dates = new double[pointCount]; var firstDay = new DateTime(2020, 1, 22); for (int i = 0; i < pointCount; i++) { dates[i] = firstDay.AddDays(i).ToOADate(); } // simulate data for each date double[] values = new double[pointCount]; Random rand = new Random(0); for (int i = 1; i < pointCount; i++) { values[i] = values[i - 1] + rand.NextDouble(); } var mplt = new ScottPlot.MultiPlot(1000, 400, 1, 2); var pltDefault = mplt.GetSubplot(0, 0); pltDefault.Title("Default xSpacing"); pltDefault.PlotScatter(dates, values); pltDefault.XAxis.DateTimeFormat(true); var pltTest = mplt.GetSubplot(0, 1); pltTest.Title("xSpacing = 1 day"); pltTest.PlotScatter(dates, values); pltTest.XAxis.DateTimeFormat(true); pltTest.XAxis.TickLabelStyle(rotation: 45); pltTest.Layout(bottom: 60); // need extra height to accomodate rotated labels // force 1 tick per day on a DateTime axis pltTest.XAxis.ManualTickSpacing(1, ScottPlot.Ticks.DateTimeUnit.Day); TestTools.SaveFig(mplt); }
private ScottPlot.MultiPlot SampleMultiPlot() { var multiplot = new ScottPlot.MultiPlot(width: 800, height: 600, rows: 2, cols: 2); // plot an increasng spread of data in each subplot Random rand = new Random(0); int pointCount = 100; for (int i = 0; i < multiplot.subplots.Length; i += 1) { double zoom = Math.Pow(i + 1, 2); multiplot.subplots[i].Title($"#{i}"); multiplot.subplots[i].AddScatter( xs: ScottPlot.DataGen.Random(rand, pointCount, multiplier: zoom, offset: -.5 * zoom), ys: ScottPlot.DataGen.Random(rand, pointCount, multiplier: zoom, offset: -.5 * zoom) ); } return(multiplot); }
public void Test_MultiPlot_MatchAxis() { ScottPlot.MultiPlot multiplot = SampleMultiPlot(); // update the lower left (index 2) plot to use the scale of the lower right (index 3) multiplot.subplots[2].SetAxisLimits(multiplot.subplots[3].GetAxisLimits()); multiplot.subplots[2].Title("#2 (matched to #3)"); string name = System.Reflection.MethodBase.GetCurrentMethod().Name; string filePath = System.IO.Path.GetFullPath(name + ".png"); multiplot.SaveFig(filePath); Console.WriteLine($"Saved {filePath}"); DisplayAxisInfo(multiplot); var matchedAxisLimits = multiplot.subplots[2].GetAxisLimits(); Assert.Greater(matchedAxisLimits.XMax, matchedAxisLimits.XMin); Assert.Greater(matchedAxisLimits.YMax, matchedAxisLimits.YMin); }