public void DrawRegressionLine()
        {
            var theta = Fit.Line(Data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), Data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray());

            var x = Expr.Variable("x");
            var a = Expr.Variable("a");
            var b = Expr.Variable("b");

            a = System.Math.Round(theta.Item2, 2);
            b = System.Math.Round(theta.Item1, 2);

            Func <double, double> fx = (a * x + b).Compile("x");

            if (_regressionPlot != null)
            {
                Series.plt.Remove(_regressionPlot);
            }

            var x1 = Data.OrderBy(d => d.Item1).First().Item1;
            var y1 = fx(Data.OrderBy(d => d.Item1).First().Item1);
            var x2 = Data.OrderBy(d => d.Item1).Last().Item1;
            var y2 = fx(Data.OrderBy(d => d.Item1).Last().Item1);

            _regressionPlot = Series.plt.PlotLine(x1, y1, x2, y2, color: System.Drawing.Color.Red);

            Series.plt.PlotText($"{System.Math.Round(fx(25), 2)}", 17, fx(25), System.Drawing.Color.Red, fontSize: 16);
            Series.Render();

            ;
        }
示例#2
0
        public void Test_Scatter_LineWidth()
        {
            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start with default settings
            double[] xs   = { 1, 2, 3, 4 };
            double[] ys   = { 1, 4, 9, 16 };
            double[] xErr = { .15, .15, .5, .5 };
            double[] yErr = { .5, .5, 1, 1 };
            var      splt = new PlottableScatter(xs, ys, xErr, yErr)
            {
            };

            plt.Add(splt);
            var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // change the plottable
            splt.lineWidth += 1;
            var bmp2 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // 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));
        }
示例#3
0
        private void OnMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var    mousePos = e.MouseDevice.GetPosition(TimetableGraph);
            double mouseX   = TimetableGraph.plt.CoordinateFromPixelX(mousePos.X);
            double mouseY   = TimetableGraph.plt.CoordinateFromPixelY(mousePos.Y);

            scatterHighLight.HighlightClear();
            var(x, y, index) = scatterHighLight.HighlightPointNearest(mouseX, mouseY);
            TimeGraphUIModel graph = highlightedTimeGraphUiModels[index];

            if (graph != null)
            {
                double[] xs = { x };
                double[] ys = { y };
                if (marker != null)
                {
                    marker.markerShape = MarkerShape.none;
                }

                marker = TimetableGraph.plt.PlotScatter(xs, ys, Color.Red,
                                                        markerShape: MarkerShape.openCircle, markerSize: 15);
                if (GraphModel.SelectedTimeGraph != null && GraphModel.SelectedTimeGraph.Plot != null)
                {
                    GraphModel.SelectedTimeGraph.Plot.lineWidth = 1;
                }
                graph.Plot.lineWidth         = 3;
                GraphModel.SelectedTimeGraph = graph;
                TimetableGraph.Render();
            }
            TimetableGraph.Render();
        }
示例#4
0
        public ToggleVisibility()
        {
            this.InitializeComponent();
#if DEBUG
            this.AttachDevTools();
#endif
            int      pointCount = 51;
            double[] dataXs     = DataGen.Consecutive(pointCount);
            double[] dataSin    = DataGen.Sin(pointCount);
            double[] dataCos    = DataGen.Cos(pointCount);

            avaPlot1 = this.Find <AvaPlot>("avaPlot1");

            sinPlot = avaPlot1.plt.PlotScatter(dataXs, dataSin);
            cosPlot = avaPlot1.plt.PlotScatter(dataXs, dataCos);
            vline1  = avaPlot1.plt.PlotVLine(0);
            vline2  = avaPlot1.plt.PlotVLine(50);

            avaPlot1.Render();

            this.Find <CheckBox>("sineCheckbox").Checked   += SinShow;
            this.Find <CheckBox>("sineCheckbox").Unchecked += SinHide;

            this.Find <CheckBox>("cosineCheckbox").Checked   += CosShow;
            this.Find <CheckBox>("cosineCheckbox").Unchecked += CosHide;

            this.Find <CheckBox>("linesCheckbox").Checked   += LinesShow;
            this.Find <CheckBox>("linesCheckbox").Unchecked += LinesHide;
        }
示例#5
0
 public static void VisibleCtrl(PlottableScatter scatterPlot,
                                PlottableScatterHighlight fittingHL, bool isChecked, FormsPlot plot)
 {
     if (scatterPlot != null && fittingHL != null)
     {
         scatterPlot.visible = isChecked;
         fittingHL.visible   = isChecked;
         plot.Render();
     }
 }
示例#6
0
        private void ShowValueOnHover_Load(object sender, EventArgs e)
        {
            int pointCount = 51;

            double[] Xs = DataGen.Consecutive(pointCount);
            double[] Ys = DataGen.Sin(pointCount, 2);
            scatterPlot = formsPlot1.plt.PlotScatter(Xs, Ys, color: Color.Blue);
            formsPlot1.plt.AxisAuto();
            formsPlot1.Render();

            // create a point and text that will be moved around to highlight the point under the cursor
            highlightedPoint = formsPlot1.plt.PlotPoint(0, 0, markerSize: 10, color: Color.Red);
            highlightedText  = formsPlot1.plt.PlotText("asdf", 0, 0, fontSize: 10, color: Color.Black);
        }
示例#7
0
        private void ToggleVisibility_Load(object sender, EventArgs e)
        {
            int pointCount = 51;

            double[] dataXs  = DataGen.Consecutive(pointCount);
            double[] dataSin = DataGen.Sin(pointCount);
            double[] dataCos = DataGen.Cos(pointCount);

            sinPlot = formsPlot1.plt.PlotScatter(dataXs, dataSin);
            cosPlot = formsPlot1.plt.PlotScatter(dataXs, dataCos);
            vline1  = formsPlot1.plt.PlotVLine(0);
            vline2  = formsPlot1.plt.PlotVLine(50);

            formsPlot1.Render();
        }
示例#8
0
        public ToggleVisibility()
        {
            InitializeComponent();

            int pointCount = 51;

            double[] dataXs  = DataGen.Consecutive(pointCount);
            double[] dataSin = DataGen.Sin(pointCount);
            double[] dataCos = DataGen.Cos(pointCount);

            sinPlot = wpfPlot1.plt.PlotScatter(dataXs, dataSin);
            cosPlot = wpfPlot1.plt.PlotScatter(dataXs, dataCos);
            vline1  = wpfPlot1.plt.PlotVLine(0);
            vline2  = wpfPlot1.plt.PlotVLine(50);

            wpfPlot1.Render();
        }
示例#9
0
        public ShowValueOnHover()
        {
            InitializeComponent();

            // plot some data
            int pointCount = 51;

            double[] Xs = DataGen.Consecutive(pointCount);
            double[] Ys = DataGen.Sin(pointCount, 2);
            scatterPlot = wpfPlot1.plt.PlotScatter(Xs, Ys, color: System.Drawing.Color.Blue);
            wpfPlot1.plt.AxisAuto();
            wpfPlot1.Render();

            // create a point and text that will be moved around to highlight the point under the cursor
            highlightedPoint         = wpfPlot1.plt.PlotPoint(0, 0, markerSize: 10, color: System.Drawing.Color.Red);
            highlightedText          = wpfPlot1.plt.PlotText("asdf", 0, 0, fontSize: 10, color: System.Drawing.Color.Black);
            highlightedPoint.visible = false;
            highlightedText.visible  = false;
        }
示例#10
0
        public void PlotGraph(ScottPlotGraph graphModel)
        {
            var locationCount = GraphModel.LocationList.Count;
            var serviceCount  = GraphModel.TimeGraphUI.Count;
            var pointCount    = locationCount * serviceCount;

            scatterDataX = new double[pointCount + 1];
            scatterDataY = new double[pointCount + 1];
            highlightedTimeGraphUiModels = new TimeGraphUIModel[pointCount + 1];
            scatterIndex = 0;
            int i = 0;

            foreach (var graph in GraphModel.TimeGraphUI)
            {
                graph.Plot = PlotService(graphModel, graph, GraphModel.TimeGraphUI[i].ServiceAbbreviation);
                i++;
            }

            PlotTimeAxis(graphModel.Zoom, graphModel.Pan);
            PlotLocationAxis(graphModel);

            if (marker != null)
            {
                //redraw marker
                marker = TimetableGraph.plt.PlotScatter(marker.xs, marker.ys, Color.Red,
                                                        markerShape: MarkerShape.openCircle, markerSize: 15);
            }

            if (GraphModel.SelectedTimeGraph != null)
            {
                GraphModel.SelectedTimeGraph.Plot.lineWidth = 3;
            }

            TimetableGraph.plt.Style(figBg: GetResourceColor("WindowBackground"));
            TimetableGraph.plt.Style(dataBg: GetResourceColor("ControlBackground"));
            TimetableGraph.plt.Grid(enable: true, color: GetResourceColor("GridLine"));
            scatterHighLight = TimetableGraph.plt.PlotScatterHighlight(scatterDataX, scatterDataY, lineWidth: 0, markerSize: 0.5);
            TimetableGraph.Configure(enablePanning: false, enableScrollWheelZoom: false, enableRightClickZoom: false);
            TimetableGraph.Render();
        }
        public MainWindowViewModel()
        {
            MoistureContent = "0";
            Data            = new ObservableCollection <Tuple <double, double> >()
            {
            };

            Series = new WpfPlot();
            Series.plt.Title("Liquid limit test", fontSize: 20);
            Series.plt.XLabel("Number of blows (N)", bold: true);
            Series.plt.YLabel("Moisture content (%)", bold: true);
            Series.plt.Ticks(logScaleY: true);
            Series.Configure(lockHorizontalAxis: true, lockVerticalAxis: true);

            Series.plt.AxisAuto(horizontalMargin: 0, verticalMargin: 0.9);

            //_dataPlot = Series.plt.PlotScatter(_data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), _data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray());

            ClearDataCommand = new DelegateCommand(() =>
            {
                NumberOfBlows   = 0;
                MoistureContent = "";
                Data.Clear();
                Series.plt.Clear();

                if (_dataPlot == null)
                {
                    _dataPlot = Series.plt.PlotScatter(Data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), Data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray());
                }
            });

            AddDataCommand = new DelegateCommand(() =>
            {
                Data.Add(new Tuple <double, double>(NumberOfBlows, Double.Parse(MoistureContent)));
                if (Data.Count() >= 2)
                {
                    Series.plt.Clear();
                    _dataPlot = Series.plt.PlotScatter(Data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), Data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray(), color: System.Drawing.Color.Gray, lineStyle: LineStyle.Dash);

                    DrawRegressionLine();
                }

                NumberOfBlows   = 0;
                MoistureContent = "0";
            });

            ExportCommand = new DelegateCommand(() =>
            {
                var dialog    = new SaveFileDialog();
                dialog.Filter = "Excel file (*.xls)|*.xls";
                dialog.ShowDialog();
                ;

                var fileName = dialog.FileName;

                if (String.IsNullOrEmpty(fileName))
                {
                    return;
                }

                Series.plt.SaveFig($"{fileName}.png");

                var book = new BinBook();

                var id = book.addPicture(fileName + ".png");

                var sheet = book.addSheet("Chart");
                sheet.setPicture(10, 3, id);

                book.save(fileName);
            });
        }