Пример #1
0
        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);
        }
Пример #2
0
        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);
        }