private static ScatterSeries CreateRandomScatterSeries(int n, MarkerType markerType, bool setSize, bool setValue, LinearColorAxis colorAxis)
        {
            var s1 = new ScatterSeries
            {
                MarkerType = markerType,
                MarkerSize = 6,
                ColorAxisKey = colorAxis != null ? colorAxis.Key : "nix"
            };
            var random = new Random(13);
            for (int i = 0; i < n; i++)
            {
                var p = new ScatterPoint((random.NextDouble() * 2.2) - 1.1, random.NextDouble());
                if (setSize)
                {
                    p.Size = (random.NextDouble() * 5) + 5;
                }

                if (setValue)
                {
                    p.Value = (random.NextDouble() * 2.2) - 1.1;
                }

                s1.Points.Add(p);
            }

            return s1;
        }
 private static PlotModel CreateRandomScatterSeriesWithColorAxisPlotModel(int n, OxyPalette palette, MarkerType markerType, AxisPosition colorAxisPosition, OxyColor highColor, OxyColor lowColor)
 {
     var model = new PlotModel { Title = string.Format("ScatterSeries (n={0})", n), Background = OxyColors.LightGray };
     var colorAxis = new LinearColorAxis { Position = colorAxisPosition, Palette = palette, Minimum = -1, Maximum = 1, HighColor = highColor, LowColor = lowColor };
     model.Axes.Add(colorAxis);
     model.Series.Add(CreateRandomScatterSeries(n, markerType, false, true, colorAxis));
     return model;
 }
 public static PlotModel TwoScatterSeries()
 {
     var model = new PlotModel { Title = "Two ScatterSeries (with and without values)", Subtitle = "With values (squares), without values (triangles)" };
     var colorAxis = new LinearColorAxis { Position = AxisPosition.Right, Key = "ColorAxis", Palette = OxyPalettes.Jet(30), Minimum = -1, Maximum = 1 };
     model.Axes.Add(colorAxis);
     model.Series.Add(CreateRandomScatterSeries(50, MarkerType.Triangle, false, false, null));
     model.Series.Add(CreateRandomScatterSeries(50, MarkerType.Square, false, true, colorAxis));
     return model;
 }
Beispiel #4
0
        public Heatmap(string title, string xTitle, string yTitle, double[,] data)
            : base(title)
        {
            var model = new PlotModel
            {
                Title = title,
            };

            OxyPalette palette = OxyPalettes.Hot(200);
            var colorAxis = new LinearColorAxis
            {
                InvalidNumberColor = OxyColors.Gray,
                Position = AxisPosition.Right,
                Palette = palette
            };
            model.Axes.Add(colorAxis);

            var xAxis = new LinearAxis
            {
                Position = AxisPosition.Bottom,
                Title = xTitle
            };
            model.Axes.Add(xAxis);

            var yAxis = new LinearAxis
            {
                Title = yTitle
            };
            model.Axes.Add(yAxis);

            var series = new HeatMapSeries
            {
                X0 = 0,
                X1 = 1,
                Y0 = 0,
                Y1 = 1,
                FontSize = .2
            };
            int width = data.GetLength(0);
            int height = data.GetLength(1);
            series.Data = new double[width, height];
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    series.Data[i, j] = data[i, j];
                }
            }

            model.Series.Add(series);
            Model = model;
        }
        public static PlotModel ConfusionMatrix()
        {
            // Example provided by Pau Climent Pérez
            // See also http://en.wikipedia.org/wiki/Confusion_matrix
            var data = new double[3, 3];

            data[0, 0] = 1;
            data[1, 1] = 0.8;
            data[1, 2] = 0.2;
            data[2, 2] = 1;

            // I guess this is where the confusion comes from?
            data = data.Transpose();

            string[] cat1 = { "class A", "class B", "class C" };

            var model = new PlotModel { Title = "Confusion Matrix" };

            var palette = OxyPalette.Interpolate(50, OxyColors.White, OxyColors.Black);

            var lca = new LinearColorAxis { Position = AxisPosition.Right, Palette = palette, HighColor = OxyColors.White, LowColor = OxyColors.White };
            model.Axes.Add(lca);

            var axis1 = new CategoryAxis { Position = AxisPosition.Top, Title = "Actual class" };
            axis1.Labels.AddRange(cat1);
            model.Axes.Add(axis1);

            // We invert this axis, so that they look "symmetrical"
            var axis2 = new CategoryAxis { Position = AxisPosition.Left, Title = "Predicted class" };
            axis2.Labels.AddRange(cat1);
            axis2.Angle = -90;
            axis2.StartPosition = 1;
            axis2.EndPosition = 0;

            model.Axes.Add(axis2);

            var hms = new HeatMapSeries
            {
                Data = data,
                Interpolate = false,
                LabelFontSize = 0.25,
                X0 = 0,
                X1 = data.GetLength(1) - 1,
                Y0 = 0,
                Y1 = data.GetLength(0) - 1,
            };

            model.Series.Add(hms);
            return model;
        }
Beispiel #6
0
        public static PlotModel ColorCodingOnScatterPlots()
        {
            var model = new PlotModel { Title = "Colour coding on scatter plots" };
            var colorAxis = new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), Minimum = 0, Maximum = 5, HighColor = OxyColors.Gray, LowColor = OxyColors.Black };
            model.Axes.Add(colorAxis);

            var s4 = new ScatterSeries { MarkerType = MarkerType.Circle };
            s4.Points.Add(new ScatterPoint(3, 5, 5, 0));
            s4.Points.Add(new ScatterPoint(5, 5, 7, 0));
            s4.Points.Add(new ScatterPoint(2, 4, 5, 0.3));
            s4.Points.Add(new ScatterPoint(3, 3, 8, 0));
            s4.Points.Add(new ScatterPoint(3, 2, 5, 0));
            s4.Points.Add(new ScatterPoint(3, 5, 8, 1));
            s4.Points.Add(new ScatterPoint(2, 2, 3, 5));
            s4.Points.Add(new ScatterPoint(1, 4, 4, 1));
            s4.Points.Add(new ScatterPoint(4, 3, 5, 3));
            s4.Points.Add(new ScatterPoint(0, 0, 1, 1));
            s4.Points.Add(new ScatterPoint(8, 8, 1, 1));
            model.Series.Add(s4);
            return model;
        }
Beispiel #7
0
        public void TestMsFeatureScatterPlot(string path1, string path2, string pngPath)
        {
            // Convert relative paths to absolute paths
            path1 = GetPath(path1);
            path2 = GetPath(path2);
            pngPath = GetPath(pngPath);

            var fiOutput = new FileInfo(pngPath);
            var didirectory = fiOutput.Directory;
            if (didirectory == null)
                throw new DirectoryNotFoundException(pngPath);

            if (!didirectory.Exists)
                didirectory.Create();

            var aligner = new LcmsWarpFeatureAligner();

            var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1);
            var aligneeMs = UmcLoaderFactory.LoadMsFeatureData(path2);
            var finder = FeatureFinderFactory.CreateFeatureFinder(FeatureFinderType.TreeBased);

            var tolerances = new FeatureTolerances
            {
                FragmentationWindowSize = .5,
                Mass = 13,
                DriftTime = .3,
                Net = .01
            };
            var options = new LcmsFeatureFindingOptions(tolerances);
            options.MaximumNetRange = .002;

            var baseline = finder.FindFeatures(baselineMs, options, null);
            var alignee = finder.FindFeatures(aligneeMs, options, null);
            var alignmentResults = aligner.Align(baseline, alignee);

            var plotModel1 = new PlotModel
            {
                Subtitle = "Interpolated, cartesian axes",
                Title = "HeatMapSeries"
            };

            var palette = OxyPalettes.Hot(200);
            var linearColorAxis1 = new LinearColorAxis
            {
                InvalidNumberColor = OxyColors.Gray,
                Position = AxisPosition.Right,
                Palette = palette
            };
            plotModel1.Axes.Add(linearColorAxis1);

            // linearColorAxis1.

            var linearAxis1 = new LinearAxis {Position = AxisPosition.Bottom};
            plotModel1.Axes.Add(linearAxis1);

            var linearAxis2 = new LinearAxis();
            plotModel1.Axes.Add(linearAxis2);

            var heatMapSeries1 = new HeatMapSeries
            {
                X0 = 0,
                X1 = 1,
                Y0 = 0,
                Y1 = 1,
                FontSize = .2
            };

            var scores = alignmentResults.heatScores;
            var width = scores.GetLength(0);
            var height = scores.GetLength(1);

            heatMapSeries1.Data = new double[width, height];

            var seriesData = heatMapSeries1.Data;
            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    seriesData[i, j] = Convert.ToDouble(scores[i, j]);
                }
            }

            plotModel1.Series.Add(heatMapSeries1);

            var svg = new SvgExporter();
            var svgString = svg.ExportToString(plotModel1);

            var xml = new XmlDocument();
            xml.LoadXml(svgString);
            var x = SvgDocument.Open(xml); // Svg.SvgDocument();
            var bmp = x.Draw();

            bmp.Save(pngPath);

            var heatmap = HeatmapFactory.CreateAlignedHeatmap(alignmentResults.heatScores);
            var netHistogram = HistogramFactory.CreateHistogram(alignmentResults.netErrorHistogram, "NET Error", "NET Error");
            var massHistogram = HistogramFactory.CreateHistogram(alignmentResults.massErrorHistogram, "Mass Error", "Mass Error (ppm)");

            var baseName = Path.Combine(didirectory.FullName, Path.GetFileNameWithoutExtension(fiOutput.Name));

            var encoder = new SvgEncoder();
            PlotImageUtility.SaveImage(heatmap, baseName + "_heatmap.svg", encoder);
            PlotImageUtility.SaveImage(netHistogram, baseName + "_netHistogram.svg", encoder);
            PlotImageUtility.SaveImage(massHistogram, baseName + "_massHistogram.svg", encoder);
        }
        private async void createPlotModel()
        {
            await Task.Run(() =>
            {
                this.dataTable = DatabaseAccesserEcolog.GetResult(createQuery());
            });
            
            calculateEnergyParameter();
            calculateTimeParameter();

            var plotModel = new PlotModel();
            plotModel.Subtitle = "SemananticLink: " + semantciLink.Semantics + ", Direction: " + direction.Direction;
            plotModel.Title = "Semantic Matrix";

            var linearColorAxis = new LinearColorAxis();
            linearColorAxis.HighColor = OxyColors.Gray;
            linearColorAxis.LowColor = OxyColors.Black;
            linearColorAxis.Position = AxisPosition.Right;
            plotModel.Axes.Add(linearColorAxis);

            var linearAxis1 = new LinearAxis();
            linearAxis1.Title = "Time";
            linearAxis1.Unit = "s";
            linearAxis1.Position = AxisPosition.Bottom;
            plotModel.Axes.Add(linearAxis1);
            var linearAxis2 = new LinearAxis();
            linearAxis2.Title = "Lost Energy";
            linearAxis2.Unit = "kWh";
            plotModel.Axes.Add(linearAxis2);

            var heatMapSeries1 = new HeatMapSeries();
            heatMapSeries1.LabelFormatString = "0";
            heatMapSeries1.X0 = minExcludedTime;
            heatMapSeries1.X1 = maxExcludedTime;
            heatMapSeries1.Y0 = minExcludedEnergy;
            heatMapSeries1.Y1 = maxExcludedEnergy;
            heatMapSeries1.LabelFontSize = 0.2;
            heatMapSeries1.Data = new Double[classNumber + 1, classNumber + 1];

            int count = 0; //  for debug

            double preTimeLevel = 0;
            double currentTimeLevel = minExcludedTime;

            for (int i = 0; i < classNumber + 1; i++)
            {
                double preEnergyLevel = 0;
                double currentEnergyLevel = minExcludedEnergy;

                for (int j = 0; j < classNumber + 1; j++)
                {
                    heatMapSeries1.Data[i, j] = dataTable.AsEnumerable()
                        .Where(x => x.Field<double>("SumLostEnergy") > preEnergyLevel)
                        .Where(x => x.Field<double>("SumLostEnergy") <= currentEnergyLevel)
                        .Where(x => x.Field<int>("TIME") > preTimeLevel)
                        .Where(x => x.Field<int>("TIME") <= currentTimeLevel).Count();

                    count += (int)heatMapSeries1.Data[i, j];

                    if (j == 0)
                    {
                        preEnergyLevel = minExcludedEnergy;
                    }
                    else
                    {
                        preEnergyLevel += classWidthEnergy;
                    }

                    currentEnergyLevel += classWidthEnergy;

                }

                if (i == 0)
                {
                    preTimeLevel = minExcludedTime;
                }
                else
                {
                    preTimeLevel += classWidthTime;
                }

                currentTimeLevel += classWidthTime;
            }

            plotModel.Series.Add(heatMapSeries1);

            this.ProgressBarVisibility = System.Windows.Visibility.Collapsed;
            this.PlotModel = plotModel;

        }
Beispiel #9
0
        public void TestLcmsWarpAlignment(string path1, string path2, string svgPath)
        {
            // Convert relative paths to absolute paths
            path1 = GetPath(path1);
            path2 = GetPath(path2);
            svgPath = GetPath(HEATMAP_RESULTS_FOLDER_BASE + svgPath);

            var aligner = new LcmsWarpFeatureAligner();

            var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1);
            var aligneeMs = UmcLoaderFactory.LoadMsFeatureData(path2);
            var finder = FeatureFinderFactory.CreateFeatureFinder(FeatureFinderType.TreeBased);

            var tolerances = new FeatureTolerances
            {
                FragmentationWindowSize = .5,
                Mass = 13,
                DriftTime = .3,
                Net = .01
            };
            var options = new LcmsFeatureFindingOptions(tolerances)
            {
                MaximumNetRange = .002
            };

            var baseline = finder.FindFeatures(baselineMs, options, null);
            var alignee = finder.FindFeatures(aligneeMs, options, null);
            var data = aligner.Align(baseline, alignee);

            var plotModel1 = new PlotModel
            {
                Subtitle = "Interpolated, cartesian axes",
                Title = "HeatMapSeries"
            };

            var palette = OxyPalettes.Hot(200);
            var linearColorAxis1 = new LinearColorAxis
            {
                InvalidNumberColor = OxyColors.Gray,
                Position = AxisPosition.Right,
                Palette = palette
            };
            plotModel1.Axes.Add(linearColorAxis1);

            // linearColorAxis1.

            var linearAxis1 = new LinearAxis {Position = AxisPosition.Bottom};
            plotModel1.Axes.Add(linearAxis1);

            var linearAxis2 = new LinearAxis();
            plotModel1.Axes.Add(linearAxis2);

            var heatMapSeries1 = new HeatMapSeries
            {
                X0 = 0,
                X1 = 1,
                Y0 = 0,
                Y1 = 1,
                FontSize = .2
            };

            var scores = data.heatScores;
            var width = scores.GetLength(0);
            var height = scores.GetLength(1);

            heatMapSeries1.Data = new double[width, height];

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    heatMapSeries1.Data[i, j] = Convert.ToDouble(scores[i, j]);
                }
            }

            plotModel1.Series.Add(heatMapSeries1);

            var svg = new SvgExporter();
            var svgString = svg.ExportToString(plotModel1);
            using (var writer = File.CreateText(svgPath + ".svg"))
            {
                writer.Write(svgString);
            }
        }
Beispiel #10
0
        public void TestSimpleCreation()
        {
            var plotModel1 = new PlotModel
            {
                PlotType = PlotType.Cartesian,
                Subtitle = "Interpolated, cartesian axes",
                Title = "HeatMapSeries"
            };

            var palette = OxyPalettes.Hot(200);
            var linearColorAxis1 = new LinearColorAxis
            {
                InvalidNumberColor = OxyColors.Gray,
                Position = AxisPosition.Right,
                Palette = palette
            };

            plotModel1.Axes.Add(linearColorAxis1);

            var linearAxis1 = new LinearAxis {Position = AxisPosition.Bottom};
            plotModel1.Axes.Add(linearAxis1);
            var linearAxis2 = new LinearAxis();
            plotModel1.Axes.Add(linearAxis2);
            var heatMapSeries1 = new HeatMapSeries
            {
                X0 = 0.0,
                X1 = 1.0,
                Y0 = 0.0,
                Y1 = 1.0,
                FontSize = .2,
                Data = new Double[2, 3]
            };
            //heatMapSeries1.LabelFontSize = 0.2;
            heatMapSeries1.Data[0, 0] = 0;
            heatMapSeries1.Data[0, 1] = 10.2;
            heatMapSeries1.Data[0, 2] = 20.4;
            heatMapSeries1.Data[1, 0] = 0.1;
            heatMapSeries1.Data[1, 1] = 0.3;
            heatMapSeries1.Data[1, 2] = 0.2;
            plotModel1.Series.Add(heatMapSeries1);

            var svg = new SvgExporter();
            var svgString = svg.ExportToString(plotModel1);

            var xml = new XmlDocument();
            xml.LoadXml(svgString);
            var x = SvgDocument.Open(xml); // Svg.SvgDocument();
            var bmp = x.Draw();
            bmp.Save(GetPath(HEATMAP_RESULTS_FOLDER_BASE + "testbmp.jpg"));

            var encoder = new PngPlotModelEncoder();
            encoder.SaveImage(plotModel1, GetPath(HEATMAP_RESULTS_FOLDER_BASE + "mine.png"));
        }
        void setupTrackPlot(OxyPlot.Wpf.PlotView plot)
        {
            var plotModel = new PlotModel { };

            plot.Model = plotModel;

            var songPointsFull = new List<ScatterPoint>();

            var songSeries = new ScatterSeries();
            songSeries.ItemsSource = songPointsFull;
            songSeries.MarkerType = MarkerType.Square;
            songSeries.MarkerSize = 0.1;

            plotModel.Series.Add(songSeries);

            var x_axis = new OxyPlot.Axes.LinearAxis()
            {
                Key = "XAxis",
                Position = OxyPlot.Axes.AxisPosition.Bottom,
                IsAxisVisible = false,
                //AbsoluteMaximum = 1800,
                //AbsoluteMinimum = -1,
                //MinorStep = 10,
            };
            var y_axis = new LinearColorAxis()
            {
                Key = "YAxis",
                Position = OxyPlot.Axes.AxisPosition.Left,
                Palette = OxyPalettes.Hue(12),
                Minimum = 0,
                Maximum = 12,
                IsAxisVisible = false

            };
            plot.ActualController.UnbindAll();
            plotModel.IsLegendVisible = false;

            plotModel.Axes.Add(x_axis);
            plotModel.Axes.Add(y_axis);
        }