コード例 #1
0
        public static PlotModel Peaks()
        {
            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            Func<double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1))
               - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y)
               - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xvalues = ArrayHelper.CreateVector(x0, x1, 0.03);
            var yvalues = ArrayHelper.CreateVector(y0, y1, 0.03);
            var peaksData = ArrayHelper.Evaluate(peaks, xvalues, yvalues);

            var model = new PlotModel("Peaks");
            model.Axes.Add(new ColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });

            var hms = new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData };
            model.Series.Add(hms);
            var cs = new ContourSeries
                {
                    Color = OxyColors.Black,
                    FontSize = 0,
                    ContourLevelStep = 1,
                    LabelBackground = null,
                    ColumnCoordinates = yvalues,
                    RowCoordinates = xvalues,
                    Data = peaksData
                };
            model.Series.Add(cs);
            return model;
        }
コード例 #2
0
        public static PlotModel LogPeaks()
        {
            Func <double, double, double> logPeaks = (x, y) => peaks(Math.Log(x) / 10, Math.Log(y) / 10);

            var model       = new PlotModel();
            var coordinates = ArrayBuilder.CreateVector(-3, 3, 0.05);

            for (var i = 0; i < coordinates.Length; i++)
            {
                coordinates[i] = Math.Exp(coordinates[i] * 10);
            }

            var cs = new ContourSeries
            {
                ColumnCoordinates = coordinates,
                RowCoordinates    = coordinates
            };

            cs.Data = ArrayBuilder.Evaluate(logPeaks, cs.ColumnCoordinates, cs.RowCoordinates);
            model.Series.Add(cs);
            model.Axes.Add(new LogarithmicAxis {
                Position = AxisPosition.Bottom
            });
            model.Axes.Add(new LogarithmicAxis {
                Position = AxisPosition.Left
            });
            return(model);
        }
コード例 #3
0
        public static PlotModel ContourSeries()
        {
            var model = new PlotModel {
                Title = "ContourSeries"
            };
            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            Func <double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xx        = ArrayBuilder.CreateVector(x0, x1, 100);
            var yy        = ArrayBuilder.CreateVector(y0, y1, 100);
            var peaksData = ArrayBuilder.Evaluate(peaks, xx, yy);

            var cs = new ContourSeries
            {
                Color             = OxyColors.Black,
                LabelBackground   = OxyColors.White,
                ColumnCoordinates = yy,
                RowCoordinates    = xx,
                Data = peaksData
            };

            model.Series.Add(cs);

            return(model);
        }
コード例 #4
0
        public SecondLabViewModel()
        {
            ChartModel = new PlotModel();

            //generate values
            var xx        = ArrayBuilder.CreateVector(MinValue, MaxValue, 10);
            var yy        = ArrayBuilder.CreateVector(MinValue, MaxValue, 10);
            var peaksData = ArrayBuilder.Evaluate((d, d1) => Function(d, d1), xx, yy);

            var cs = new ContourSeries
            {
                Color             = OxyColors.Black,
                LabelBackground   = OxyColors.White,
                ColumnCoordinates = yy,
                RowCoordinates    = xx,
                Data = peaksData
            };

            ChartModel.Series.Add(cs);

            var solutions = new ScatterSeries
            {
                MarkerType = MarkerType.Circle,
                MarkerFill = OxyColor.FromRgb(0xFF, 0, 0)
            };

            ChartModel.Series.Add(solutions);

            ChartModel.Series.Add(new ScatterSeries());
        }
コード例 #5
0
        public static PlotModel CreatePeaks(OxyPalette palette = null, bool includeContours = true, int n = 100)
        {
            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            Func<double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xvalues = ArrayBuilder.CreateVector(x0, x1, n);
            var yvalues = ArrayBuilder.CreateVector(y0, y1, n);
            var peaksData = ArrayBuilder.Evaluate(peaks, xvalues, yvalues);

            var model = new PlotModel { Title = "Peaks" };
            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = palette ?? OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });

            var hms = new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData };
            model.Series.Add(hms);
            if (includeContours)
            {
                var cs = new ContourSeries
                             {
                                 Color = OxyColors.Black,
                                 FontSize = 0,
                                 ContourLevelStep = 1,
                                 LabelBackground = OxyColors.Undefined,
                                 ColumnCoordinates = yvalues,
                                 RowCoordinates = xvalues,
                                 Data = peaksData
                             };
                model.Series.Add(cs);
            }

            return model;
        }
コード例 #6
0
        Task RenderContour(Series plot)
        {
            var contourSeries = new ContourSeries
            {
                Data = plot.Config.Data,
                ColumnCoordinates = plot.Config.ColumnCoordinates,
                RowCoordinates    = plot.Config.RowCoordinates
            };

            OxyplotModel.Series.Add(contourSeries);

            return(Task.CompletedTask);
        }
コード例 #7
0
 public static PlotModel Peaks()
 {
     var model = new PlotModel { Title = "Peaks" };
     var cs = new ContourSeries
         {
             ColumnCoordinates = ArrayHelper.CreateVector(-3, 3, 0.05),
             RowCoordinates = ArrayHelper.CreateVector(-3.1, 3.1, 0.05)
         };
     cs.Data = ArrayHelper.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
     model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
     model.Series.Add(cs);
     return model;
 }
コード例 #8
0
        public static PlotModel OpenContours()
        {
            var model = new PlotModel();
            var cs    = new ContourSeries
            {
                ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
                RowCoordinates    = ArrayBuilder.CreateVector(-3, 3, 0.05)
            };

            cs.Data = ArrayBuilder.Evaluate(openContours, cs.ColumnCoordinates, cs.RowCoordinates);
            model.Series.Add(cs);
            return(model);
        }
コード例 #9
0
 public static PlotModel InvisibleContourSeries()
 {
     var model = new PlotModel { Title = "Invisible contour series" };
     var cs = new ContourSeries
     {
         IsVisible = false,
         ColumnCoordinates = ArrayBuilder.CreateVector(-1, 1, 0.05),
         RowCoordinates = ArrayBuilder.CreateVector(-1, 1, 0.05)
     };
     cs.Data = ArrayBuilder.Evaluate((x, y) => x + y, cs.ColumnCoordinates, cs.RowCoordinates);
     model.Series.Add(cs);
     return model;
 }
コード例 #10
0
        public MainViewModel()
        {
            this.MyModel = new PlotModel {
                Title = "ContourSeries"
            };

            this.MyModel.Axes.Add(new LinearColorAxis
            {
                Position = OxyPlot.Axes.AxisPosition.Right,
                //Palette = OxyPalettes.Jet(500)
                Palette = OxyPalettes.Rainbow(100)
            });

            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;

            //generate values
            Func <double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xx        = ArrayBuilder.CreateVector(x0, x1, 100);
            var yy        = ArrayBuilder.CreateVector(y0, y1, 100);
            var peaksData = ArrayBuilder.Evaluate(peaks, xx, yy);


            var heatMapSeries = new HeatMapSeries
            {
                X0           = x0,
                X1           = x1,
                Y0           = y0,
                Y1           = y1,
                Interpolate  = true,
                RenderMethod = HeatMapRenderMethod.Bitmap,
                Data         = peaksData
            };

            this.MyModel.Series.Add(heatMapSeries);


            var cs = new ContourSeries
            {
                Color             = OxyColors.Black,
                LabelBackground   = OxyColors.Transparent,
                ColumnCoordinates = yy,
                RowCoordinates    = xx,
                Data = peaksData
            };

            this.MyModel.Series.Add(cs);
        }
コード例 #11
0
 public static PlotModel PeaksWithColors()
 {
     var model = new PlotModel { Title = "Peaks" };
     var cs = new ContourSeries
     {
         ColumnCoordinates = ArrayHelper.CreateVector(-3, 3, 0.05),
         RowCoordinates = ArrayHelper.CreateVector(-3.1, 3.1, 0.05),
         ContourColors = new[] { OxyColors.SeaGreen, OxyColors.RoyalBlue, OxyColors.IndianRed }
     };
     cs.Data = ArrayHelper.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
     model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
     model.Series.Add(cs);
     return model;
 }
コード例 #12
0
 public static PlotModel WideArrayPeaks()
 {
     var model = new PlotModel { Title = "Peaks" };
     model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -3.16262, Maximum = 3.162 });
     var cs = new ContourSeries
     {
         ColumnCoordinates = ArrayHelper.CreateVector(-3, 3, 0.05),
         RowCoordinates = ArrayHelper.CreateVector(-1, 1, 0.05)
     };
     cs.Data = ArrayHelper.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
     model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
     model.Series.Add(cs);
     return model;
 }
コード例 #13
0
        public static PlotModel InvisibleContourSeries()
        {
            var model = new PlotModel("Invisible contour series");
            var cs    = new ContourSeries
            {
                IsVisible         = false,
                ColumnCoordinates = global::OxyPlot.ArrayHelper.CreateVector(-1, 1, 0.05),
                RowCoordinates    = global::OxyPlot.ArrayHelper.CreateVector(-1, 1, 0.05)
            };

            cs.Data = global::OxyPlot.ArrayHelper.Evaluate((x, y) => x + y, cs.ColumnCoordinates, cs.RowCoordinates);
            model.Series.Add(cs);
            return(model);
        }
コード例 #14
0
        public static PlotModel InvisibleContourSeries()
        {
            var model = new PlotModel {
                Title = "Invisible contour series"
            };
            var cs = new ContourSeries
            {
                IsVisible         = false,
                ColumnCoordinates = ArrayBuilder.CreateVector(-1, 1, 0.05),
                RowCoordinates    = ArrayBuilder.CreateVector(-1, 1, 0.05)
            };

            cs.Data = ArrayBuilder.Evaluate((x, y) => x + y, cs.ColumnCoordinates, cs.RowCoordinates);
            model.Series.Add(cs);
            return(model);
        }
コード例 #15
0
        public static PlotModel Peaks()
        {
            var model = new PlotModel {
                Title = "Peaks"
            };
            var cs = new ContourSeries
            {
                ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
                RowCoordinates    = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05)
            };

            cs.Data        = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
            model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
            model.Series.Add(cs);
            return(model);
        }
コード例 #16
0
        public static PlotModel PeaksWithColors()
        {
            var model = new PlotModel {
                Title = "Peaks"
            };
            var cs = new ContourSeries
            {
                ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
                RowCoordinates    = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05),
                ContourColors     = new[] { OxyColors.SeaGreen, OxyColors.RoyalBlue, OxyColors.IndianRed }
            };

            cs.Data        = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
            model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
            model.Series.Add(cs);
            return(model);
        }
コード例 #17
0
        public static PlotModel Peaks()
        {
            Func<double, double, double> peaks = (x, y) =>
               3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1))
               - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y)
               - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);

            var model = new PlotModel("Peaks");
            var cs = new ContourSeries
                {
                    ColumnCoordinates = ArrayHelper.CreateVector(-3, 3, 0.05),
                    RowCoordinates = ArrayHelper.CreateVector(-3.1, 3.1, 0.05)
                };
            cs.Data = ArrayHelper.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
            model.Series.Add(cs);
            return model;
        }
コード例 #18
0
        protected override void UpdateSeries()
        {
            var model = _model.Model;

            model.Series.Clear();

            for (var i = 0; i < _plot.Count; i++)
            {
                var n      = 0;
                var points = _plot[i];
                var series = new ContourSeries();
                var y      = new List <Double>();
                var x      = new List <Double>();

                for (var j = 0; j < points.Count; j++)
                {
                    if (y.Count == 0 || points[j].X > y[y.Count - 1])
                    {
                        y.Add(points[j].X);
                    }

                    if (x.Count == 0 || points[j].Y > x[x.Count - 1])
                    {
                        x.Add(points[j].Y);
                    }
                }

                var z = new Double[y.Count, x.Count];

                for (var k = 0; k < y.Count; k++)
                {
                    for (var l = 0; l < x.Count; l++)
                    {
                        z[k, l] = points[n++].Magnitude;
                    }
                }

                series.RowCoordinates    = y.ToArray();
                series.ColumnCoordinates = x.ToArray();
                series.Data              = z;
                series.ContourLevels     = _plot.Levels;
                series.LabelFormatString = "0.000";
                UpdateSeries(series, points);
                model.Series.Add(series);
            }
        }
コード例 #19
0
        public static PlotModel Peaks()
        {
            Func <double, double, double> peaks = (x, y) =>
                                                  3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1))
                                                  - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y)
                                                  - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);

            var model = new PlotModel("Peaks");
            var cs    = new ContourSeries
            {
                ColumnCoordinates = ArrayHelper.CreateVector(-3, 3, 0.05),
                RowCoordinates    = ArrayHelper.CreateVector(-3.1, 3.1, 0.05)
            };

            cs.Data = ArrayHelper.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
            model.Series.Add(cs);
            return(model);
        }
コード例 #20
0
ファイル: FireDesignView.cs プロジェクト: MagmaWorks/ACE
        public void LoadGraph(Column c)
        {
            plotModel = new PlotModel();
            TP        = new TemperatureProfile(c.LX / 1000, c.LY / 1000, c.R * 60, c.FireCurve);
            //generate values
            var cs = new ContourSeries
            {
                Color             = OxyColors.Black,
                LabelBackground   = OxyColors.White,
                ColumnCoordinates = TP.Y.AsArray(),
                RowCoordinates    = TP.X.AsArray(),
                Data = TP.Temp.ToArray()
            };

            cs.RenderInLegend   = false;
            cs.ContourLevelStep = 100;
            plotModel.Series.Add(cs);
            RaisePropertyChanged(nameof(PlotModel));
        }
コード例 #21
0
        public static PlotModel PeaksWithColors()
        {
            Func <double, double, double> peaks = (x, y) =>
                                                  3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1))
                                                  - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y)
                                                  - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);

            var model = new PlotModel("Peaks");
            var cs    = new ContourSeries
            {
                ColumnCoordinates = global::OxyPlot.ArrayHelper.CreateVector(-3, 3, 0.05),
                RowCoordinates    = global::OxyPlot.ArrayHelper.CreateVector(-3.1, 3.1, 0.05),
                ContourColors     = new[] { OxyColors.SeaGreen, OxyColors.RoyalBlue, OxyColors.IndianRed }
            };

            cs.Data = global::OxyPlot.ArrayHelper.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
            model.Series.Add(cs);
            return(model);
        }
コード例 #22
0
        void UpdateSeries(ContourSeries series, IPointSeries points)
        {
            series.StrokeThickness = points.LineWidth;
            series.Title           = points.Label;
            series.ContourColors   = _plot.ColorPalette.GenerateOxyColors(_plot.Levels.Length);

            if (_plot.ShowLevel)
            {
                series.FontSize        = Double.NaN;
                series.LabelBackground = OxyColor.FromArgb(220, 255, 255, 255);
            }
            else
            {
                series.FontSize        = 0;
                series.LabelBackground = OxyColors.Transparent;
            }

            series.CalculateContours();
        }
コード例 #23
0
        public static PlotModel WideArrayPeaks()
        {
            var model = new PlotModel {
                Title = "Peaks"
            };

            model.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, Minimum = -3.16262, Maximum = 3.162
            });
            var cs = new ContourSeries
            {
                ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
                RowCoordinates    = ArrayBuilder.CreateVector(-1, 1, 0.05)
            };

            cs.Data        = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
            model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
            model.Series.Add(cs);
            return(model);
        }
コード例 #24
0
        public static PlotModel CreatePeaks(OxyPalette palette = null, bool includeContours = true, int n = 100)
        {
            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            Func <double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xvalues   = ArrayBuilder.CreateVector(x0, x1, n);
            var yvalues   = ArrayBuilder.CreateVector(y0, y1, n);
            var peaksData = ArrayBuilder.Evaluate(peaks, xvalues, yvalues);

            var model = new PlotModel {
                Title = "Peaks"
            };

            model.Axes.Add(new LinearColorAxis {
                Position = AxisPosition.Right, Palette = palette ?? OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black
            });

            var hms = new HeatMapSeries {
                X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData
            };

            model.Series.Add(hms);
            if (includeContours)
            {
                var cs = new ContourSeries
                {
                    Color             = OxyColors.Black,
                    FontSize          = 0,
                    ContourLevelStep  = 1,
                    LabelBackground   = OxyColors.Undefined,
                    ColumnCoordinates = yvalues,
                    RowCoordinates    = xvalues,
                    Data = peaksData
                };
                model.Series.Add(cs);
            }

            return(model);
        }
コード例 #25
0
        public static PlotModel Peaks()
        {
            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            Func <double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1))
                                                  - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y)
                                                  - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xvalues   = global::OxyPlot.ArrayHelper.CreateVector(x0, x1, 0.03);
            var yvalues   = global::OxyPlot.ArrayHelper.CreateVector(y0, y1, 0.03);
            var peaksData = global::OxyPlot.ArrayHelper.Evaluate(peaks, xvalues, yvalues);

            var model = new PlotModel("Peaks");

            model.Axes.Add(new ColorAxis {
                Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black
            });

            var hms = new HeatMapSeries {
                X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData
            };

            model.Series.Add(hms);
            var cs = new ContourSeries
            {
                Color             = OxyColors.Black,
                FontSize          = 0,
                ContourLevelStep  = 1,
                LabelBackground   = null,
                ColumnCoordinates = yvalues,
                RowCoordinates    = xvalues,
                Data = peaksData
            };

            model.Series.Add(cs);
            return(model);
        }
コード例 #26
0
        public PlotModel PrepareAccelerationGraphFor(double ld, IList <TestSeries> testSeries)
        {
            var m = new PlotModel
            {
                Title = "Maximale Beschleunigung",
                Axes  =
                {
                    new LinearAxis {
                        Position = AxisPosition.Left, Title = "Geschwindigkeit (m/s)", Minimum = testSeries.Min(s => s.EntrySpeed), Maximum = testSeries.Max(s => s.EntrySpeed)
                    },
                    new LinearAxis {
                        Position = AxisPosition.Bottom, Title = "Eintrittswinkel (°)", Minimum = testSeries.Min(s => - s.EntryAngle), Maximum = testSeries.Max(s => - s.EntryAngle)
                    }
                }
            };
            var angles            = testSeries.Where(s => s.LiftToDragCoefficient == ld).Select(s => - s.EntryAngle).Distinct().ToArray();
            var speeds            = testSeries.Where(s => s.LiftToDragCoefficient == ld).Select(s => (double)s.EntrySpeed).Distinct().ToArray();
            var max               = testSeries.Max(s => s.MaxAccleration);
            var accelerationTable = CalculateAccelerationTable(ld, angles, speeds, testSeries);
            var minColor          = OxyColor.FromArgb(0xff, 0x00, 0xdb, 0xff);
            var maxColor          = OxyColor.FromArgb(0xff, 0xff, 0x72, 0x00);
            var contours          = GenerateContours(0.0, max, minColor, maxColor, 30);
            var cs = new ContourSeries
            {
                ColumnCoordinates = angles,
                RowCoordinates    = speeds,
                Data              = accelerationTable,
                ContourLevels     = contours.Select(c => c.Limit).ToArray(),
                ContourColors     = contours.Select(c => c.Color).ToArray(),
                LabelFormatString = "F1",
                RenderInLegend    = true
            };

            cs.CalculateContours();
            m.Series.Add(cs);
            return(m);
        }
コード例 #27
0
        public static PlotModel ContourSeries()
        {
            var model = new PlotModel { Title = "ContourSeries" };
            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            Func<double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xx = ArrayBuilder.CreateVector(x0, x1, 100);
            var yy = ArrayBuilder.CreateVector(y0, y1, 100);
            var peaksData = ArrayBuilder.Evaluate(peaks, xx, yy);

            var cs = new ContourSeries
            {
                Color = OxyColors.Black,
                LabelBackground = OxyColors.White,
                ColumnCoordinates = yy,
                RowCoordinates = xx,
                Data = peaksData
            };
            model.Series.Add(cs);

            return model;
        }
コード例 #28
0
ファイル: Issues.cs プロジェクト: huoxudong125/oxyplot
        public static PlotModel IndexOutOfRangeContour()
        {
            var model = new PlotModel { Title = "Issue #42" };
            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(5) });

            var x = ArrayBuilder.CreateVector(0, 1, 20);
            var y = ArrayBuilder.CreateVector(-1, 1, 2);
            var data = ArrayBuilder.Evaluate((a, b) => a * b, x, y);

            var contour = new ContourSeries
            {
                ColumnCoordinates = y,
                RowCoordinates = x,
                Data = data
            };
            model.Series.Add(contour);

            return model;
        }
コード例 #29
0
        private void DoSearchHarmonyOnClick(object sender, RoutedEventArgs e)
        {
            int nrOfIterations = 10; //tu zmiana jesli wiecej wypisać iteracji

            result.Text = string.Empty;

            AmelioratedHarmonySearch ahs = new AmelioratedHarmonySearch(values, expression, decisionVariableQty,
                                                                        xL, xU, hmcr, parMIN, parMAX, bwMIN,
                                                                        bwMAX, NI, HMS);

            ahs.ImprovedHarmonySearch();
            List <double[]> listPoints = ahs.GetFirstAndLastIterationResults();

            if (NI > 2 * nrOfIterations)
            {
                WriteToResultTextBlock($"FIRST ITERATIONS: {Environment.NewLine}");
                for (int i = 1; i < nrOfIterations + 1; i++)
                {
                    WriteToResultTextBlock($"Result for iteration nr {i}");
                    WriteResultForAllVector(listPoints[i]);
                    WriteToResultTextBlock($"{Environment.NewLine}");
                }

                WriteToResultTextBlock($"LAST ITERATIONS: {Environment.NewLine}");
                for (int i = nrOfIterations + 1; i < 2 * nrOfIterations + 1; i++)
                {
                    WriteToResultTextBlock($"Result for iteration nr {NI - 2 * nrOfIterations + i}");
                    WriteResultForAllVector(listPoints[i]);
                    WriteToResultTextBlock($"{Environment.NewLine}");
                }
            }

            WriteToResultTextBlock($"First solution: ");
            WriteResultForAllVector(listPoints.First());
            WriteToResultTextBlock($"{Environment.NewLine}");


            WriteToResultTextBlock($"Optimal solution: ");
            WriteResultForAllVector(listPoints.Last());
            WriteToResultTextBlock($"{Environment.NewLine}");


            if (decisionVariableQty == 2)
            {
                var tmp = new PlotModel();

                tmp.Axes.Add(new LinearColorAxis
                {
                    Position = AxisPosition.Right,
                    Palette  = OxyPalettes.Cool(200)
                });

                double tmpMaxValue = Double.MinValue;

                var x1x1 = ArrayBuilder.CreateVector(xL[0], xU[0], 100);
                var x2x2 = ArrayBuilder.CreateVector(xL[1], xU[1], 100);
                double[,] peaksData = new double[x1x1.GetLength(0), x2x2.GetLength(0)];
                double[] xy_tab = new double[2];

                for (int i = 0; i < x1x1.GetLength(0); i++)
                {
                    for (int j = 0; j < x2x2.GetLength(0); j++)
                    {
                        xy_tab[0]       = x1x1[i];
                        xy_tab[1]       = x2x2[j];
                        peaksData[i, j] = function.calculate(xy_tab);
                        if (peaksData[i, j] > tmpMaxValue)
                        {
                            tmpMaxValue = peaksData[i, j];
                        }
                    }
                }

                var heatMapSeries = new HeatMapSeries
                {
                    X0           = xL[0],
                    X1           = xU[0],
                    Y0           = xL[1],
                    Y1           = xU[1],
                    Interpolate  = true,
                    RenderMethod = HeatMapRenderMethod.Bitmap,
                    Data         = peaksData
                };
                tmp.Series.Add(heatMapSeries);

                var cs = new ContourSeries
                {
                    Color             = OxyColors.BlueViolet,
                    LabelBackground   = OxyColors.Transparent,
                    ColumnCoordinates = x1x1,
                    RowCoordinates    = x2x2,
                    Data = peaksData
                };
                tmp.Series.Add(cs);

                var path = new LineSeries
                {
                    ItemsSource     = ahs.GetDataPoints(),
                    Color           = OxyColors.Black,
                    StrokeThickness = 2
                };
                tmp.Series.Add(path);

                var sc = new ScatterSeries
                {
                    BinSize               = 10,
                    MarkerType            = MarkerType.Cross,
                    MarkerStrokeThickness = 3,
                };
                sc.Points.Add(new ScatterPoint(ahs.GetBestX1(), ahs.GetBestX2(), 5, tmpMaxValue));
                tmp.Series.Add(sc);

                GetMainViewModel().MyModel = tmp;
            }

            CountBtn.IsEnabled = false;
        }
コード例 #30
0
        //
        // Funkcja wywoływana przez wątek do rysowania wykresów - tutaj plotujemy model
        //
        void worker_DoWork2(object sender, DoWorkEventArgs e)
        {
            plotBusy = true; // wątek rysowania jest zajęty

            // Tymczasowe równanie - jest nadpisywane w różnych miejscach kodu
            eq = new org.mariuszgromada.math.mxparser.Expression(equationString);

            // Lista tokenów (argumentów) dodawana do listy łańcuchów znaków argumentów
            List <Token> tokensList = eq.getCopyOfInitialTokens();

            foreach (Token t in tokensList)
            {
                if (t.tokenTypeId == Token.NOT_MATCHED)
                {
                    if (!argumentsString.Contains(t.tokenStr))
                    {
                        argumentsString.Add(t.tokenStr);
                    }
                }
            }

            // Rozdzielenie argumentów przecinkami
            commaSeparatedArguments = string.Join(", ", argumentsString);

            // Utworzenie funkcji na podstawie argumentów i równania
            f = new Function("f(" + commaSeparatedArguments + ") = " + equationString);

            // Wyłapywanie błędów równania
            if (argumentsString.ToArray().Length < 1)
            {
                argumentsString.Clear();
                argumentsString = new List <string>();
                equationString  = "";
                eq = new org.mariuszgromada.math.mxparser.Expression();
                System.GC.Collect(); // <- Garbage Collector
                algorithm.ClearAlgorithm();
                return;
            }
            if (!eq.checkLexSyntax())
            {
                argumentsString.Clear();
                argumentsString = new List <string>();
                equationString  = "";
                eq = new org.mariuszgromada.math.mxparser.Expression();
                System.GC.Collect(); // <- Garbage Collector
                algorithm.ClearAlgorithm();
                return;
            }
            if (eq.checkSyntax())
            {
                argumentsString.Clear();
                argumentsString = new List <string>();
                equationString  = "";
                eq = new org.mariuszgromada.math.mxparser.Expression();
                System.GC.Collect(); // <- Garbage Collector
                algorithm.ClearAlgorithm();
                return;
            }
            foreach (var arg in argumentsString)
            {
                if (arg.Length < 2 || !arg.Contains("x"))
                {
                    argumentsString.Clear();
                    argumentsString = new List <string>();
                    equationString  = "";
                    eq = new org.mariuszgromada.math.mxparser.Expression();
                    System.GC.Collect(); // <- Garbage Collector
                    algorithm.ClearAlgorithm();
                    return;
                }
            }

            // Jeśli liczba argumentów > 1 to rysujemy warstwice
            if (arguments.ToArray().Length > 1)
            {
                model.Title = "Warstwice: ";                // tytuł modelu to warstwice
                List <double[]> xy = new List <double[]>(); // lista tablic zmiennych double przechowująca minimum i maximum konkretnych argumentów

                // Zapisywanie tych zmiennych jest potrzebne do określenia granic wykresów
                foreach (var arg in arguments)
                {
                    xy.Add(ArrayBuilder.CreateVector(arg.Minimum, arg.Maximum, p));
                }

                // Pomocnicza tablica łańcuchów znaków argumentów funkcji (trochę czarów się tutaj dzieje)
                // Finalnie infunc powinien zawierać łańcuchy znaków postaci:
                //      Przykład dla 2 argumentów: 0.125, 1.216
                //      Przykład dla 3 argumentów: 0.125, 1.216, 0
                //      Przykład dla 4 argumentów: 0.125, 1.216, 0, 0
                // Zera na końcu są wstawiane dlatego, że spłaszczamy wielowymiarowy wykres do postaci warstwic
                var infunc = new string[p, p];
                for (int i = 0; i < p; ++i)
                {
                    for (int j = 0; j < p; ++j)
                    {
                        for (int k = 0; k < xy.ToArray().Length; ++k)
                        {
                            // Jeśli jest to pierwszy argument to dodajemy go po prostu do łańcucha znaków
                            if (k == 0)
                            {
                                infunc[i, j] += xy[k][i].ToString().Replace(',', '.');
                            }
                            // Jeżeli jest to drugi argument to dodajemy go do łańcucha znaków z przecinkiem przed wartością
                            if (k == 1)
                            {
                                infunc[i, j] += "," + xy[k][j].ToString().Replace(',', '.');
                            }
                            // Jeżeli jest to każdy kolejny argument to dodajemy 0 do łańcucha znaków z przecinkiem przed
                            if (k > 1)
                            {
                                infunc[i, j] += ", 0";
                            }
                        }
                    }
                }

                // Tablica zawierająca wyrażenia do obliczenia - korzysta z poprzedniej tablicy pomocniczej do określenia tych wyrażeń
                var data = new double[p, p];
                for (int i = 0; i < p; ++i)
                {
                    for (int j = 0; j < p; ++j)
                    {
                        int progressPercentage = Convert.ToInt32(((double)i / p) * 100);
                        org.mariuszgromada.math.mxparser.Expression equa = new org.mariuszgromada.math.mxparser.Expression("f(" + infunc[i, j] + ")", f);
                        data[i, j] = equa.calculate();
                        (sender as BackgroundWorker).ReportProgress(progressPercentage);
                    }
                }

                buffer = new PositionsBuffer();
                sigma  = data;

                // Tworzenie zmiennej kontur - wykorzystywana do rysowania warstwic
                var cs = new ContourSeries
                {
                    Color             = OxyColors.Red,
                    LabelBackground   = OxyColors.White,
                    ColumnCoordinates = xy[0],
                    RowCoordinates    = xy[1],
                    Data = data
                };
                // Dodanie kontur do modelu
                model.Series.Add(cs);
            }
            // Jeśli liczba argumentów = 1 to rysujemy wykres
            else
            {
                p           = p * 30;                            // zmieniamy dokładność na 30-krotnie większą od ustalonej ze względu na mniejszą złożoność obliczeniową
                model.Title = "Wykres: ";                        // tytuł modelu to wykres
                LineSeries      series1 = new LineSeries();      // zmienna lineseries używana do rysowania wykresów
                List <double[]> xy      = new List <double[]>(); // lista tablic tak jak w poprzednim przypadku - tutaj przechowuje tylko jeden argument, ale zachowanie konwencji ułatwiło dalsze zadania
                foreach (var arg in arguments)
                {
                    xy.Add(ArrayBuilder.CreateVector(arg.Minimum, arg.Maximum, p));
                }

                // Tak samo jak powyżej
                var infunc = new string[p];
                for (int i = 0; i < p; ++i)
                {
                    infunc[i] = xy[0][i].ToString().Replace(',', '.');
                }

                // Tak samo jak powyżej
                var data = new double[p];
                for (int i = 0; i < p; ++i)
                {
                    int progressPercentage = Convert.ToInt32(((double)i / p) * 100);
                    org.mariuszgromada.math.mxparser.Expression equa = new org.mariuszgromada.math.mxparser.Expression("f(" + infunc[i] + ")", f);
                    data[i] = equa.calculate();
                    (sender as BackgroundWorker).ReportProgress(progressPercentage);
                }

                // Lista wygenerowanych punktów dodawana do zmiennej typu lineseries w celu wygenerowania wykresu
                List <DataPoint> pnts = new List <DataPoint>();
                for (int i = 0; i < p; ++i)
                {
                    series1.Points.Add(new DataPoint(xy[0][i], data[i]));
                }
                // Kolor wykresu ustalamy na czerwony - tak żeby wykresy i warstwice były tego samego koloru
                series1.Color = OxyColors.Red;
                model.Series.Add(series1);
                p = p / 30; // przywracamy domyślną wartość zmiennej odpowiadającej za dokładność wykresu
            }

            // Czyścimy listę argumentów w postaci łańcuchów znaków
            argumentsString.Clear();
            // Czyścimy wyrażenie
            eq = new org.mariuszgromada.math.mxparser.Expression();
            // Zapisujemy utworzony model w wyniku wątku rysowania
            e.Result = model;
        }
コード例 #31
0
ファイル: PlotVM.cs プロジェクト: whidbey/OxyPlotNoesisGUI
	public PlotVM()
	{
		this.PlotModel1 = new PlotModel { Title = "OxyTest" };
		this.PlotModel1.Series.Add(new FunctionSeries(GetValue, 0, 10, 0.1, "cos(x)"));
		this.PlotModel1.Series.Add(new FunctionSeries((d)=> Math.Sin(d+offset1), 0, 10, 0.1, "sin(x)"));

		// Create some data
		this.Items = new List<Item>
		{
			new Item {Label = "Apples", Value1 = 37, Value2 = 12, Value3 = 19},
			new Item {Label = "Pears", Value1 = 7, Value2 = 21, Value3 = 9},
			new Item {Label = "Bananas", Value1 = 23, Value2 = 2, Value3 = 29}
		};

		// Create the plot model
		var tmp = new PlotModel { Title = "Bar series", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical };

		// Add the axes, note that MinimumPadding and AbsoluteMinimum should be set on the value axis.
		tmp.Axes.Add(new CategoryAxis { Position = AxisPosition.Left, ItemsSource = this.Items, LabelField = "Label" });
		tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0, AbsoluteMinimum = 0 });

		// Add the series, note that the BarSeries are using the same ItemsSource as the CategoryAxis.
		tmp.Series.Add(new BarSeries { Title = "2009", ItemsSource = this.Items, ValueField = "Value1" });
		tmp.Series.Add(new BarSeries { Title = "2010", ItemsSource = this.Items, ValueField = "Value2" });
		tmp.Series.Add(new BarSeries { Title = "2011", ItemsSource = this.Items, ValueField = "Value3" });

		this.PlotModel2 = tmp;

		// Create some data
		this.Items2 = new List<BoxPlotItem>
		{
			new BoxPlotItem(1, 13.0, 15.5, 17.0, 18.5, 19.5) { Mean = 18.0 },
			new BoxPlotItem(2, 13.0, 15.5, 17.0, 18.5, 19.5),
			new BoxPlotItem(3, 12.0, 13.5, 15.5, 18.0, 20.0) { Mean = 14.5 },
			new BoxPlotItem(4, 12.0, 13.5, 15.5, 18.0, 20.0) { Mean = 14.5, Outliers = new List<double> { 11.0, 21.0, 21.5 } },
			new BoxPlotItem(5, 13.5, 14.0, 14.5, 15.5, 16.5) { Outliers = new List<double> { 17.5, 18.0, 19.0 } }
		};


		var model = new PlotModel { Title = "ContourSeries" };
		double x0 = -3.1;
		double x1 = 3.1;
		double y0 = -3;
		double y1 = 3;
		Func<double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
		var xx = ArrayBuilder.CreateVector(x0, x1, 100);
		var yy = ArrayBuilder.CreateVector(y0, y1, 100);
		var peaksData = ArrayBuilder.Evaluate(peaks, xx, yy);

		var cs = new ContourSeries
		{
			StrokeThickness = 4,
			Color = OxyColors.Black,
			LabelBackground = OxyColors.White,
			ColumnCoordinates = yy,
			RowCoordinates = xx,
			Data = peaksData
		};
		model.Series.Add(cs);

		this.PlotModel3 = model;
		this.PlotModel3.InvalidatePlot(true);

		// Create the plot model
		tmp = new PlotModel { Title = "BoxPlot series", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical };

		// Add the axes, note that MinimumPadding and AbsoluteMinimum should be set on the value axis.
		tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0.3, MaximumPadding = 0.3, AbsoluteMinimum = 0 });
		tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0.3, MaximumPadding = 0.3, AbsoluteMinimum = 0 });

		// Add the series, note that the BarSeries are using the same ItemsSource as the CategoryAxis.
		tmp.Series.Add(new BoxPlotSeries { Title = "Values", ItemsSource = this.Items2, Fill = OxyColors.LightBlue });

		this.PlotModel4 = tmp;
		this.PlotModel4.InvalidatePlot(true);
	}
コード例 #32
0
        private void bt_showmap_Click(object sender, EventArgs e)
        {
            bool   success = true;
            double Imax    = 0;

            success = success && double.TryParse(tb_Imax.Text, out Imax);
            double Umax = 0;

            success = success && double.TryParse(tb_Umax.Text, out Umax);
            double max_speed = 0;

            success = success && double.TryParse(tb_maxSpeed.Text, out max_speed);

            string config = string.Format("{0},{1},{2}", Imax, Umax, max_speed);

            MapType maptype = MapType.power;

            Enum.TryParse <MapType>(comboBox_maptype.Text, true, out maptype);

            if (!success)
            {
                MessageBox.Show("Error parse text to double");
                return;
            }

            var mtpa = buildTableMaxtorquePerAmple();

            int    n  = 100;
            double x0 = 0;
            double x1 = max_speed;
            double y0 = 0;
            double y1 = mtpa.GetMaxTorqueWithCurrentMagnitude(Imax);

            if (last_config != config)
            {
                effMap      = buildEfficiencyMap(50, 100, Imax, Umax, max_speed);
                last_config = config;
            }

            var    data  = effMap.power;
            string title = "Power (W)";

            switch (maptype)
            {
            case MapType.power:
                data  = effMap.power;
                title = "Power (W)";
                break;

            case MapType.efficiency:
                data  = effMap.efficiency;
                title = "Efficiency (%)";
                break;

            case MapType.windingloss:
                data  = effMap.windingloss;
                title = "Winding loss (W)";
                break;

            case MapType.rotor_coreloss:
                data  = effMap.rotor_coreloss;
                title = "Rotor core loss (W)";
                break;

            case MapType.stator_coreloss:
                data  = effMap.stator_coreloss;
                title = "Stator loss (W)";
                break;

            case MapType.coreloss:
                data  = effMap.coreloss;
                title = "Core loss (W)";
                break;

            case MapType.total_loss:
                data  = effMap.totalloss;
                title = "Total loss (W)";
                break;

            case MapType.voltage:
                data  = effMap.voltage;
                title = "Voltage (V)";
                break;

            case MapType.current:
                data  = effMap.current;
                title = "Current (A)";
                break;

            case MapType.beta:
                data  = effMap.beta;
                title = "Beta (degree)";
                break;

            case MapType.Ld:
                data  = effMap.Ld;
                title = "Ld (mH)";
                break;

            case MapType.Lq:
                data  = effMap.Lq;
                title = "Ld (mH)";
                break;

            default:
                break;
            }

            double fmin = double.MaxValue;

            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    if (data[i, j] >= 0 && fmin > data[i, j])
                    {
                        fmin = data[i, j];
                    }
                }
            }

            var model = new PlotModel
            {
                Title = title,
            };

            model.Axes.Add(new LinearColorAxis
            {
                Position  = AxisPosition.Right,
                Palette   = OxyPalettes.Jet(500),
                HighColor = OxyColors.Gray,
                LowColor  = OxyColors.White,
                Minimum   = fmin,
                //Maximum = 100,
                Title = title
            });

            model.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Bottom,
                Title    = "Speed",
                //MajorGridlineStyle = LineStyle.Solid,
                //MinorGridlineStyle = LineStyle.Solid,
                //MajorGridlineColor = OxyColor.FromAColor(40, c),
                //MinorGridlineColor = OxyColor.FromAColor(20, c)
            });

            model.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Left,
                Title    = "Torque",
                //AbsoluteMinimum = 0,
                //Minimum = 0,
                //MajorGridlineStyle = LineStyle.Solid,
                //MinorGridlineStyle = LineStyle.Solid,
                //MajorGridlineColor = OxyColor.FromAColor(40, c),
                //MinorGridlineColor = OxyColor.FromAColor(20, c)
            });

            var hms = new HeatMapSeries
            {
                X0          = x0,
                X1          = x1,
                Y0          = y0,
                Y1          = y1,
                Data        = data,
                Interpolate = true,
            };

            model.Series.Add(hms);

            // contour
            var cs = new ContourSeries
            {
                //Color = OxyColors.Gray,
                //FontSize = 12,
                //ContourLevelStep = double.NaN,
                //LabelBackground = OxyColors.White,
                ColumnCoordinates = effMap.speed_points,
                RowCoordinates    = effMap.torque_points,
                Data = data,
            };

            if (cs.Data == effMap.efficiency)
            {
                cs.ContourLevels = new double[] { 0, 20, 40, 60, 80, 90, 91, 92, 93, 94, 95, 95.2, 95.4, 95.6, 95.8, 96, 96.2, 97, 98, 99 };
                model.Series.Add(cs);
            }

            // max-torque capability curve
            MaxtorqueCapabilityCurve mtcc = buildMaxtorqueCapabilityCurve(100, Imax, Umax, max_speed);
            var mtcc_series = new LineSeries()
            {
                LineStyle       = LineStyle.Solid,
                Color           = OxyColor.FromArgb(255, 0, 0, 0),
                StrokeThickness = 3,
            };

            for (int i = 0; i < mtcc.speeds.Count; i++)
            {
                mtcc_series.Points.Add(new OxyPlot.DataPoint(mtcc.speeds[i], mtcc.maxtorques[i]));
            }
            model.Series.Add(mtcc_series);

            // voltage limit curve 1
            VoltageLimitCurve vlc = buildVoltageLimitCurve(100, Imax, Umax, max_speed);
            var vlc_series        = new LineSeries()
            {
                LineStyle       = LineStyle.Dash,
                StrokeThickness = 1,
            };

            for (int i = 0; i < vlc.speeds.Count; i++)
            {
                vlc_series.Points.Add(new OxyPlot.DataPoint(vlc.speeds[i], vlc.torques[i]));
            }
            model.Series.Add(vlc_series);

            plot.Model = model;
        }
コード例 #33
0
        private void Plot_btn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var tmp = new PlotModel {
                    Title = "Contour Plot", Subtitle = "f(x1,x2)"
                };

                tmp.Axes.Add(new LinearColorAxis
                {
                    Position = OxyPlot.Axes.AxisPosition.Right,
                    //Palette = OxyPalettes.Jet(500)
                    Palette = OxyPalettes.Rainbow(100)
                });
                double[] PVBmax  = ParsePVB(PVBmax_TextBox.Text, ';');
                double[] PVBmin  = ParsePVB(PVBmin_TextBox.Text, ';');
                bool     errFlag = false;
                for (int i = 0; i < PVBmax.Length; i++)
                {
                    if (PVBmax[i] <= PVBmin[i])
                    {
                        errFlag = true;
                    }
                }
                String   fun_str = ObjFun_ComboBox.Text.ToString();
                Function fn      = new Function(fun_str);
                double   x1_min;
                double   x1_max;
                double   x2_min;
                double   x2_max;
                double   tmpMaxValue = Double.MinValue;

                if (PVBmin.GetLength(0) == 2 && !errFlag)
                {
                    x1_min = PVBmin[0];
                    x1_max = PVBmax[0];
                    x2_min = PVBmin[1];
                    x2_max = PVBmax[1];
                    var x1x1 = ArrayBuilder.CreateVector(x1_min, x1_max, 100);
                    var x2x2 = ArrayBuilder.CreateVector(x2_min, x2_max, 100);
                    double[,] peaksData = new double[x1x1.GetLength(0), x2x2.GetLength(0)];
                    double[] xy_tab = new double[2];

                    for (int i = 0; i < x1x1.GetLength(0); i++)
                    {
                        for (int j = 0; j < x2x2.GetLength(0); j++)
                        {
                            xy_tab[0]       = x1x1[i];
                            xy_tab[1]       = x2x2[j];
                            peaksData[i, j] = HarmonyTool.EvaluateFun(fn, xy_tab);
                            if (peaksData[i, j] > tmpMaxValue)
                            {
                                tmpMaxValue = peaksData[i, j];
                            }
                        }
                    }


                    var heatMapSeries = new HeatMapSeries
                    {
                        X0           = x1_min,
                        X1           = x1_max,
                        Y0           = x2_min,
                        Y1           = x2_max,
                        Interpolate  = true,
                        RenderMethod = HeatMapRenderMethod.Bitmap,
                        Data         = peaksData
                    };
                    tmp.Series.Add(heatMapSeries);


                    var cs = new ContourSeries
                    {
                        Color             = OxyColors.Black,
                        LabelBackground   = OxyColors.Transparent,
                        ColumnCoordinates = x1x1,
                        RowCoordinates    = x2x2,
                        Data = peaksData
                    };
                    tmp.Series.Add(cs);

                    if (solutionCheckBox.IsChecked == true)
                    {
                        var sc = new ScatterSeries
                        {
                            MarkerType = MarkerType.Circle
                        };
                        sc.BinSize               = 10;
                        sc.MarkerType            = MarkerType.Cross;
                        sc.MarkerStrokeThickness = 3;
                        sc.MarkerStroke          = OxyColors.Black;
                        double x1 = bestSolution[0];
                        double x2 = bestSolution[1];
                        sc.Points.Add(new OxyPlot.Series.ScatterPoint(x1, x2, 5, tmpMaxValue));
                        tmp.Series.Add(sc);
                    }
                    GetMainViewModel().MyModel = tmp;
                }
                else
                {
                    MessageBox.Show("Number of variables does not equal n = 2 or PVB not given correctly! Check forms", "Exception", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("A handled exception just occurred: " + ex.Message + "\n Check if forms are filled properly! Domain of function has to be set in PVB forms", "Exception", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
コード例 #34
0
        //bool showXAxis = true, showYAxix = true, isZoomable = true, isMovable = true;
        //IPlotType chart;
        //public bool ShowXAxis
        //{
        //    get => showXAxis;
        //    set
        //    {
        //        if (showXAxis == value) return;
        //        showXAxis = value;
        //    }
        //}
        //public bool ShowYAxix
        //{
        //    get => showYAxix;
        //    set
        //    {
        //        if (showYAxix == value) return;
        //        showYAxix = value;
        //    }
        //}
        //public bool IsZoomable
        //{
        //    get => isZoomable;
        //    set
        //    {
        //        if (isZoomable == value) return;
        //        isZoomable = value;
        //    }
        //}
        //public bool IsMovable
        //{
        //    get => isMovable;
        //    set
        //    {
        //        if (isMovable == value) return;
        //        isMovable = value;
        //    }
        //}

        public async Task Add(PlotModel plotModel)
        {
            this.oxyplotModel       = new OxyPlot.PlotModel();
            this.oxyplotModel.Title = plotModel.Title;
            foreach (var chart in plotModel.Series)
            {
                if (chart is TwoColorArea) //it should be placed before Area if clause
                {
                    var twoColorAreaSeries = new TwoColorAreaSeries
                    {
                        Color  = ChartColor.CastToOxyColor(((TwoColorArea)chart).Color),
                        Color2 = ChartColor.CastToOxyColor(((TwoColorArea)chart).Color2),
                        Limit  = ((TwoColorArea)chart).Limit
                    };
                    foreach (var item in ((TwoColorArea)chart).Data)
                    {
                        twoColorAreaSeries.Points.Add(item);
                    }
                    this.oxyplotModel.Series.Add(twoColorAreaSeries);
                }
                else if (chart is Area)
                {
                    var areaSeries = new AreaSeries();
                    foreach (var point in ((Area)chart).Data)
                    {
                        areaSeries.Points.Add(point);
                    }
                    this.oxyplotModel.Series.Add(areaSeries);
                }
                else if (chart is TwoColorLine)//it should be placed before line if clause
                {
                    var twoColorLineSeries = new TwoColorLineSeries
                    {
                        Color  = ChartColor.CastToOxyColor(((TwoColorLine)chart).Color),
                        Color2 = ChartColor.CastToOxyColor(((TwoColorLine)chart).Color2),
                        Limit  = ((TwoColorLine)chart).Limit
                    };
                    foreach (var item in ((TwoColorLine)chart).Data)
                    {
                        twoColorLineSeries.Points.Add(item);
                    }
                    this.oxyplotModel.Series.Add(twoColorLineSeries);
                }
                else if (chart is Line)
                {
                    var lineSeries = new LineSeries
                    {
                        MarkerType   = MarkerType.Circle,
                        MarkerSize   = 4,
                        MarkerStroke = OxyColors.White
                    };

                    foreach (var point in ((Line)chart).Data)
                    {
                        lineSeries.Points.Add(point);
                    }
                    this.oxyplotModel.Series.Add(lineSeries);
                }
                else if (chart is Pie)
                {
                    var pieSeries = new PieSeries();
                    foreach (var slice in ((Pie)chart).Data)
                    {
                        pieSeries.Slices.Add(slice);
                    }
                    this.oxyplotModel.Series.Add(pieSeries);
                }
                else if (chart is Bar)
                {
                    var barSeries = new BarSeries();
                    foreach (var item in ((Bar)chart).Data)
                    {
                        barSeries.Items.Add(item);
                    }
                    this.oxyplotModel.Series.Add(barSeries);
                }
                else if (chart is ErrorColumn)
                {
                    var errorColumn = new ErrorColumnSeries();
                    foreach (ErrorColumnItem item in ((ErrorColumn)chart).Data)
                    {
                        errorColumn.Items.Add((OxyPlot.Series.ErrorColumnItem)item);
                    }
                    this.oxyplotModel.Series.Add(errorColumn);
                }
                else if (chart is Column)
                {
                    var barSeries = new ColumnSeries();
                    foreach (var item in ((Column)chart).Data)
                    {
                        barSeries.Items.Add(item);
                    }
                    this.oxyplotModel.Series.Add(barSeries);
                }
                else if (chart is Box)
                {
                    var boxSeries = new BoxPlotSeries();
                    foreach (var item in ((Box)chart).Data)
                    {
                        boxSeries.Items.Add(item);
                    }
                    this.oxyplotModel.Series.Add(boxSeries);
                }
                else if (chart is Contour)
                {
                    var contourSeries = new ContourSeries
                    {
                        Data = ((Contour)chart).Data,
                        ColumnCoordinates = ((Contour)chart).ColumnCoordinates,
                        RowCoordinates    = ((Contour)chart).RowCoordinates
                    };
                    this.oxyplotModel.Series.Add(contourSeries);
                }
                else if (chart is RectangleBar)
                {
                    var rectangleBarSeries = new RectangleBarSeries
                    {
                        Title = ((RectangleBar)chart).Title
                    };
                    foreach (var item in ((RectangleBar)chart).Data)
                    {
                        rectangleBarSeries.Items.Add(item);
                    }
                    this.oxyplotModel.Series.Add(rectangleBarSeries);
                }
                else if (chart is CandleStick)
                {
                    var candleStickSeries = new CandleStickSeries();
                    foreach (var item in ((CandleStick)chart).Data)
                    {
                        candleStickSeries.Items.Add(item);
                    }
                    this.oxyplotModel.Series.Add(candleStickSeries);
                }
                else if (chart is HeatMap)
                {
                    var heatMapSeries = new HeatMapSeries()
                    {
                        Data         = ((HeatMap)chart).Data,
                        X0           = ((HeatMap)chart).X0,
                        X1           = ((HeatMap)chart).X1,
                        Y0           = ((HeatMap)chart).Y0,
                        Y1           = ((HeatMap)chart).Y1,
                        Interpolate  = ((HeatMap)chart).Interpolate,
                        RenderMethod = ((HeatMap)chart).RenderMethod
                    };
                    this.oxyplotModel.Series.Add(heatMapSeries);
                }
                else if (chart is HighLow)
                {
                    var highLowSeries = new HighLowSeries();
                    foreach (var item in ((HighLow)chart).Data)
                    {
                        highLowSeries.Items.Add(item);
                    }
                    this.oxyplotModel.Series.Add(highLowSeries);
                }
                else if (chart is IntervalBar)
                {
                    var intervalBarSeries = new IntervalBarSeries();
                    foreach (var item in ((IntervalBar)chart).Data)
                    {
                        intervalBarSeries.Items.Add(item);
                    }
                    this.oxyplotModel.Series.Add(intervalBarSeries);
                }
                else if (chart is Scatter)
                {
                    var scatterSeries = new ScatterSeries();
                    foreach (var item in ((Scatter)chart).Data)
                    {
                        scatterSeries.Points.Add(item);
                    }
                    this.oxyplotModel.Series.Add(scatterSeries);
                }
            }
            foreach (var axis in plotModel.Axes)
            {
                this.oxyplotModel.Axes.Add(axis);
            }
        }