Exemplo n.º 1
0
        public PlotModel GetOxyplotModel()
        {
            var model = new PlotModel();

            foreach (var ds in DataSeries)
            {
                var series = new ScatterErrorSeries();

                foreach (var dp in ds.DataPoints)
                {
                    if (dp.HasErrors)
                    {
                        series.Points.Add(new ScatterErrorPoint(dp.X, dp.Y, dp.ErrorX.Average(), dp.ErrorY.Average()));
                    }
                    else
                    {
                        series.Points.Add(new ScatterErrorPoint(dp.X, dp.Y, 0, 0));
                    }
                }

                model.Series.Add(series);
            }

            foreach (var axis in GetAxes())
            {
                model.Axes.Add(axis.GetOxyPlotAxis());
            }

            return(model);
        }
Exemplo n.º 2
0
        public void TestSimpleCase()
        {
            IEnumerable <object> x    = new object[] { 0d, 1d, 2d };
            IEnumerable <object> y    = new object[] { 1d, 2d, 4d };
            IEnumerable <object> xerr = new object[] { 0.25, 0.5, 0.75 };
            IEnumerable <object> yerr = new object[] { 0.5, 0.25, 0.125 };
            Line          line        = new Line(LineType.Solid, LineThickness.Thin);
            LineThickness bar         = LineThickness.Thin;
            LineThickness stopper     = LineThickness.Normal;
            Marker        marker      = new Marker(MarkerType.Cross, MarkerSize.Normal, 1);

            ErrorSeries input  = new ErrorSeries("asdf", Color.Blue, true, x, y, line, marker, bar, stopper, xerr, yerr, "", "");
            var         output = exporter.Export(input, AxisLabelCollection.Empty()).Result;

            Assert.NotNull(output);
            Assert.True(output is ScatterErrorSeries);
            ScatterErrorSeries errorSeries = (ScatterErrorSeries)output;

            Assert.AreEqual("asdf", errorSeries.Title);
            Assert.AreEqual(3, errorSeries.ItemsSource.Count());

            // Marker style
            Assert.AreEqual(OxyPlot.MarkerType.Cross, errorSeries.MarkerType);
            Assert.AreEqual(7, errorSeries.MarkerSize);

            // Line style TBI

            // Bar style
            Assert.AreEqual(0.25, errorSeries.ErrorBarStrokeThickness);

            // TBI: stopper thickness

            // Colours
            Assert.AreEqual(OxyColors.Blue, errorSeries.ErrorBarColor);
        }
Exemplo n.º 3
0
            public void ScatterErrorSeries()
            {
                var s1 = new OxyPlot.Series.ScatterErrorSeries();
                var s2 = new ScatterErrorSeries();

                OxyAssert.PropertiesAreEqual(s1, s2);
            }
Exemplo n.º 4
0
 void UpdateScatterSeries(ScatterErrorSeries series, IPointSeries points)
 {
     UpdateXySeries(series, points);
     series.ErrorBarColor         = points.Color.OxyColorFromString();
     series.MarkerType            = (MarkerType)((int)points.Symbol);
     series.MarkerFill            = series.ErrorBarColor;
     series.MarkerSize            = 3.0;
     series.MarkerStroke          = series.ErrorBarColor;
     series.MarkerStrokeThickness = 1.0;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Creates an example model with the specified number of points.
        /// </summary>
        /// <param name="n">The n.</param>
        /// <returns>A plot model.</returns>
        private static PlotModel RandomPointsAndError(int n)
        {
            var model = new PlotModel {
                Title = "ScatterErrorSeries", Subtitle = string.Format("Random data (n={0})", n), LegendPosition = LegendPosition.LeftTop
            };

            var s1 = new ScatterErrorSeries {
                Title = "Measurements"
            };

            s1.Points.AddRange(CreateScatterErrorPoints(n));
            model.Series.Add(s1);
            return(model);
        }
Exemplo n.º 6
0
        private static ScatterErrorSeries CreateErrorSeries(
            IEnumerable <DataErrorPoint> data, OxyColor color)
        {
            var aColor      = OxyColor.FromAColor(ERROR_COLOR_ALPHA, color);
            var errorSeries = new ScatterErrorSeries
            {
                MarkerSize              = ERROR_MARKER_SIZE,
                MarkerFill              = aColor,
                ErrorBarColor           = aColor,
                ErrorBarStrokeThickness = ERROR_STROKE_THICKNESS
            };

            errorSeries.Points.AddRange(data.Select(d => d.Error));
            return(errorSeries);
        }
Exemplo n.º 7
0
        public void TestSeriesWithThisData(IEnumerable <double> x, IEnumerable <double> y, IEnumerable <double> xerr, IEnumerable <double> yerr)
        {
            Line          line    = new Line(LineType.Solid, LineThickness.Thin);
            LineThickness bar     = LineThickness.Thin;
            LineThickness stopper = LineThickness.Normal;
            Marker        marker  = new Marker(MarkerType.Cross, MarkerSize.Normal, 1);

            ErrorSeries input  = new ErrorSeries("asdf", Color.Blue, true, x, y, line, marker, bar, stopper, xerr, yerr, "", "");
            var         output = exporter.Export(input, AxisLabelCollection.Empty()).Result;

            Assert.NotNull(output);
            Assert.True(output is ScatterErrorSeries);
            ScatterErrorSeries series = (ScatterErrorSeries)output;

            int n = x.Count();

            Assert.AreEqual(n, series.ItemsSource.Count());
            IEnumerable <ScatterErrorPoint> points = series.ItemsSource.Cast <ScatterErrorPoint>();
            bool havexError = xerr != null && xerr.Any();
            bool haveyError = yerr != null && yerr.Any();

            IEnumerator <double>            enumeratorX      = x.GetEnumerator();
            IEnumerator <double>            enumeratorY      = y.GetEnumerator();
            IEnumerator <ScatterErrorPoint> seriesEnumerator = points.GetEnumerator();
            IEnumerator <double>            enumeratorXErr   = xerr?.GetEnumerator();
            IEnumerator <double>            enumeratorYErr   = yerr?.GetEnumerator();

            while (enumeratorX.MoveNext() && enumeratorY.MoveNext() && seriesEnumerator.MoveNext() &&
                   (!havexError || enumeratorXErr.MoveNext()) &&
                   (!haveyError || enumeratorYErr.MoveNext()))
            {
                ScatterErrorPoint point = seriesEnumerator.Current;
                Assert.AreEqual(enumeratorX.Current, point.X);
                Assert.AreEqual(enumeratorY.Current, point.Y);
                double expectedXerr = havexError ? enumeratorXErr.Current : 0;
                double expectedYerr = haveyError ? enumeratorYErr.Current : 0;
                Assert.AreEqual(expectedXerr, point.ErrorX);
                Assert.AreEqual(expectedYerr, point.ErrorY);
            }
            Assert.False(enumeratorX.MoveNext(), "X input has more data");
            Assert.False(enumeratorY.MoveNext(), "Y input has more data");
            Assert.False(seriesEnumerator.MoveNext(), "Series has more data");
        }
Exemplo n.º 8
0
        protected override void UpdateSeries()
        {
            var model = _model.Model;

            model.Series.Clear();

            for (var i = 0; i < _plot.Count; i++)
            {
                var points = _plot[i];
                var series = new ScatterErrorSeries();

                for (var j = 0; j < points.Count; j++)
                {
                    var point = new ScatterErrorPoint(points[j].X, points[j].Y, points[j].Xerr, points[j].Yerr);
                    series.Points.Add(point);
                }

                UpdateScatterSeries(series, points);
                model.Series.Add(series);
            }
        }
Exemplo n.º 9
0
 public void ScatterErrorSeries()
 {
     var s1 = new OxyPlot.Series.ScatterErrorSeries();
     var s2 = new ScatterErrorSeries();
     OxyAssert.PropertiesAreEqual(s1, s2);
 }
        /// <summary>
        /// Creates an example model with the specified number of points.
        /// </summary>
        /// <param name="n">The n.</param>
        /// <returns>A plot model.</returns>
        private static PlotModel RandomPointsAndError(int n)
        {
            var model = new PlotModel { Title = "ScatterErrorSeries", Subtitle = string.Format("Random data (n={0})", n), LegendPosition = LegendPosition.LeftTop };

            var s1 = new ScatterErrorSeries { Title = "Measurements" };
            s1.Points.AddRange(CreateScatterErrorPoints(n));
            model.Series.Add(s1);
            return model;
        }
Exemplo n.º 11
0
        public void Visualize(Dictionary <string, double[]> x, Dictionary <string, double[]> y, Dictionary <string, double[]> yse,
                              Dictionary <string, OxyColor> color, Dictionary <string, Type> seriestype, Dictionary <string, double> linewidth, Dictionary <string, LineStyle> linestyle,
                              string title = "", string xtitle = "", string ytitle = "", bool isclear = true, LegendPosition legendposition = LegendPosition.RightTop)
        {
            if (!Visible)
            {
                Visible        = true;
                Parent.Visible = true;
            }
            if (isclear)
            {
                Model.Series.Clear();
                ylo = double.NaN; yhi = double.NaN; xlo = double.NaN; xhi = double.NaN;
            }

            foreach (var u in y.Keys.ToList())
            {
                var point = new ScatterSeries()
                {
                    Title                 = u,
                    MarkerSize            = linewidth[u],
                    MarkerFill            = color[u],
                    MarkerStrokeThickness = 0,
                    MarkerType            = MarkerType.Circle,
                    TrackerFormatString   = "{0}\nX: {2:0.0}\nY: {4:0.0}"
                };
                var line = new LineSeries()
                {
                    Title               = u,
                    StrokeThickness     = linewidth[u],
                    Color               = color[u],
                    LineStyle           = linestyle[u],
                    TrackerFormatString = "{0}\nX: {2:0.0}\nY: {4:0.0}"
                };
                var error = new ScatterErrorSeries()
                {
                    ErrorBarStopWidth       = 2,
                    ErrorBarStrokeThickness = linewidth[u],
                    ErrorBarColor           = OxyColor.FromAColor(180, line.Color),
                    MarkerSize          = 0,
                    TrackerFormatString = "{0}\nX: {2:0.0}\nY: {4:0.0}"
                };

                for (var i = 0; i < x[u].Length; i++)
                {
                    if (seriestype[u] == typeof(ScatterSeries))
                    {
                        point.Points.Add(new ScatterPoint(x[u][i], y[u][i]));
                    }
                    else if (seriestype[u] == typeof(LineSeries))
                    {
                        line.Points.Add(new DataPoint(x[u][i], y[u][i]));
                    }
                    var cyse = 0.0;
                    if (yse != null && yse.ContainsKey(u))
                    {
                        error.Points.Add(new ScatterErrorPoint(x[u][i], y[u][i], 0, yse[u][i]));
                        cyse = yse[u][i];
                    }
                    if (yhi == double.NaN)
                    {
                        yhi = y[u][i] + cyse;
                        ylo = y[u][i] - cyse;
                    }
                    if (xhi == double.NaN)
                    {
                        xhi = x[u][i];
                        xlo = x[u][i];
                    }
                    yhi = Math.Max(yhi, y[u][i] + cyse);
                    ylo = Math.Min(ylo, y[u][i] - cyse);
                    xhi = Math.Max(xhi, x[u][i]);
                    xlo = Math.Min(xlo, x[u][i]);
                }
                if (point.Points.Count > 0)
                {
                    Model.Series.Add(point);
                }
                if (line.Points.Count > 0)
                {
                    Model.Series.Add(line);
                }
                if (error.Points.Count > 0)
                {
                    Model.Series.Add(error);
                }
            }

            if (Model.DefaultXAxis != null)
            {
                Model.DefaultXAxis.Maximum = xhi + 0.01 * (xhi - xlo);
                Model.DefaultXAxis.Minimum = xlo - 0.01 * (xhi - xlo);
                Model.DefaultYAxis.Maximum = yhi + 0.01 * (yhi - ylo);
                Model.DefaultYAxis.Minimum = ylo - 0.01 * (yhi - ylo);
                Model.DefaultXAxis.Reset();
                Model.DefaultYAxis.Reset();
            }

            if (!isupdated)
            {
                if (Model.DefaultXAxis != null)
                {
                    Model.DefaultXAxis.MaximumPadding = 0.005;
                    Model.DefaultXAxis.MinimumPadding = 0.005;
                    Model.DefaultYAxis.MaximumPadding = 0.005;
                    Model.DefaultYAxis.MinimumPadding = 0.005;
                    Model.DefaultXAxis.TickStyle      = OxyPlot.Axes.TickStyle.Outside;
                    Model.DefaultXAxis.Title          = xtitle;
                    Model.DefaultYAxis.TickStyle      = OxyPlot.Axes.TickStyle.Outside;
                    Model.DefaultYAxis.Title          = ytitle;
                    Model.Title          = title;
                    Model.LegendPosition = legendposition;
                    isupdated            = true;
                }
            }
            Model.InvalidatePlot(true);
        }