コード例 #1
0
        /// <summary>
        /// Writes the plot.
        /// </summary>
        /// <param name="plot">The plot.</param>
        public void WritePlot(PlotFigure plot)
        {
            this.WriteStartFigure();
            switch (this.PlotElementType)
            {
            case HtmlPlotElementType.Embed:
            case HtmlPlotElementType.Object:
                // TODO: need a Func<string,Stream> to provide streams for the plot files?

                ////string source = string.Format(
                ////    "{0}_Plot{1}.svg", Path.GetFileNameWithoutExtension(this.outputFile), plot.FigureNumber);
                ////plot.PlotModel.SaveSvg(this.GetFullFileName(source), plot.Width, plot.Height, this.textMeasurer);
                ////this.WriteStartElement(this.PlotElementType == HtmlPlotElementType.Embed ? "embed" : "object");
                ////this.WriteAttributeString("src", source);
                ////this.WriteAttributeString("type", "image/svg+xml");
                ////this.WriteEndElement();
                break;

            case HtmlPlotElementType.Svg:
                this.WriteRaw(SvgExporter.ExportToString(plot.PlotModel, plot.Width, plot.Height, false, this.textMeasurer));
                break;
            }

            this.WriteEndFigure(plot.FigureText);
        }
コード例 #2
0
        public void SaveImage(PlotModel model, string path)
        {
            var exporter = new SvgExporter();
            var svgData  = exporter.ExportToString(model);

            File.WriteAllText(path, svgData);
        }
コード例 #3
0
ファイル: PlotModelExtensions.cs プロジェクト: wolf9s/oxyplot
        /// <summary>
        /// Creates an SVG string.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="width">The width (points).</param>
        /// <param name="height">The height (points).</param>
        /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param>
        /// <returns>A <see cref="string" />.</returns>
        public static string ToSvg(this PlotModel model, double width, double height, bool isDocument)
        {
            var rc = new GraphicsRenderContext {
                RendersToScreen = false
            };

            return(SvgExporter.ExportToString(model, width, height, isDocument, rc));
        }
コード例 #4
0
        public void ExportToString_TestPlot_ValidSvgString()
        {
            var plotModel = new PlotModel("Test plot");

            plotModel.Series.Add(new FunctionSeries(Math.Sin, 0, Math.PI * 8, 200, "Math.Sin"));
            var rc  = new ShapesRenderContext(null);
            var svg = SvgExporter.ExportToString(plotModel, 800, 500, false, rc);

            SvgAssert.IsValidElement(svg);
        }
コード例 #5
0
        public void ExportToString_TestPlot_ValidSvgString()
        {
            var plotModel = new PlotModel {
                Title = "Test plot"
            };

            plotModel.Series.Add(new FunctionSeries(Math.Sin, 0, Math.PI * 8, 200, "Math.Sin"));
            var svg = SvgExporter.ExportToString(plotModel, 800, 500, false);

            SvgAssert.IsValidElement(svg);
        }
コード例 #6
0
        public async Task SaveToFileAsync()
        {
            var svgPath = AudiogramPathUtil.GetSvgFilePath(LastUsedPath);
            var svg     = SvgExporter.ExportToString(PlotModel, 1920, 1280, true,
                                                     new SilverlightRenderContext(new InkPresenter()));

            var file = await storageFolder.CreateFileAsync(svgPath, CreationCollisionOption.ReplaceExisting);

            using (var stream = await file.OpenStreamForWriteAsync())
                using (var writer = new StreamWriter(stream))
                {
                    await writer.WriteAsync(svg);
                }
        }
コード例 #7
0
        public static string GetOxyPlotSvg <G, M, RF>(this IDensity <G, M, RF> d, string title)
            where G :
        IBaseStructure <M>,
        IRealEmbedding <M, RF>
            where M :
        struct
            where RF :
        struct
        {
            var oxyplot     = d.OxyPlot(title);
            var svgExporter = new SvgExporter {
                Width = 600, Height = 400
            };
            var res = svgExporter.ExportToString(oxyplot);

            return(res);
        }
コード例 #8
0
        static void Main(string[] args)
        {
            var df = DataFrame.ReadCsv("airquality.csv");

            Console.WriteLine("Shape: {0}", df.Shape);
            Console.WriteLine("Columns: {0}", string.Join(",", df.Columns));

            Console.WriteLine("df.iloc[0, 1] = {0}", df.iloc[0, 1]);
            Console.WriteLine("df.loc[0, 'Ozone'] = {0}", df.loc[0, "Ozone"]);

            var monthColumn = df["Month"];
            var min         = (double)(DvInt4)monthColumn.Aggregate(AggregatedFunction.Min).Get(0); // Syntax should be improved.
            var max         = (double)(DvInt4)monthColumn.Aggregate(AggregatedFunction.Max).Get(0); // Syntax should be improved.

            df["MonthFrac"] = (df["Month"] - min) / (max - min);
            Console.WriteLine("Head\n{0}", df.Head());
            var gr = df.GroupBy(new[] { "MonthFrac" }).Sum();

            Console.WriteLine("Grouped by MonthFrac\n{0}", gr);

            var gr2 = df.Drop(new[] { "Ozone", "Solar_R" }).Copy().GroupBy(new[] { "MonthFrac" }).Sum();

            Console.WriteLine("Grouped by MonthFrac, no Ozone\n{0}", gr2);

            var plot = new PlotModel {
                Title = "Simple Graph"
            };
            var serie = new ScatterSeries();

            serie.Points.AddRange(Enumerable.Range(0, gr.Shape.Item1).Select(i => new ScatterPoint((double)gr2.iloc[i, 0], (float)gr2.iloc[i, 2])));
            plot.Series.Add(serie);
            plot.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom, Title = gr2.Columns[0]
            });
            plot.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, Title = gr2.Columns[2]
            });

            var plotString = SvgExporter.ExportToString(plot, 600, 400, true);

            File.WriteAllText("graph2.svg", plotString);
        }
コード例 #9
0
        public static void SvgWriter(PlotModel model, object caller, string suffix, IEnumerable <DataPoint>[] pointData, [CallerMemberName] string callerName = "")
        {
            var directory = caller.GetType().Name;

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            var image = new SvgExporter {
                Width = 600, Height = 400
            };
            var name = $"./{directory}/{callerName}-{suffix}";

            File.WriteAllText($"{name}.svg", image.ExportToString(model));

            // Save point data as csv
            for (int i = 0; i < model.Series.Count; i++)
            {
                LineSeries serie = (LineSeries)model.Series[i];
                Frame.FromRecords(pointData[i]).SaveCsv($"{name}-{serie.Title}.csv");
            }
        }
コード例 #10
0
        public void TestSimpleCreation()
        {
            var random = new Random();
            var points = new List <int> {
                100, 1000, 10000, 100000
            };

            foreach (var totalPoints in points)
            {
                var start      = DateTime.Now;
                var plotModel1 = new PlotModel {
                    Subtitle = "No 'binning'", Title = "ScatterSeries (n=32768)"
                };

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

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

                var scatterSeries1 = new ScatterSeries
                {
                    MarkerSize            = 1,
                    MarkerStrokeThickness = 0,
                    MarkerType            = MarkerType.Diamond,
                    Title = "Series 1" + totalPoints
                };

                var pointList = new List <ScatterPoint>();
                for (var i = 0; i < totalPoints; i++)
                {
                    var xPos  = random.NextDouble();
                    var yPos  = random.NextDouble();
                    var point = new ScatterPoint(xPos, yPos);
                    pointList.Add(point);
                }
                Console.WriteLine();

                var end = DateTime.Now;
                Console.WriteLine("Creation Part of Test Took: {0:.00} seconds for {1} points",
                                  end.Subtract(start).TotalSeconds, totalPoints);

                start = DateTime.Now;
                scatterSeries1.Points.AddRange(pointList);
                plotModel1.Series.Add(scatterSeries1);
                end = DateTime.Now;
                Console.WriteLine("Scatter Plot Part of Test Took: {0:.00} seconds for {1} points",
                                  end.Subtract(start).TotalSeconds, totalPoints);

                start = DateTime.Now;
                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();
                var outputFilePath = GetPath(@"testResults\ScatterPlot\testScatter" + totalPoints + ".jpg");
                bmp.Save(outputFilePath);

                end = DateTime.Now;
                Console.WriteLine("Saving Part of Test Took: {0:.00} seconds for {1} points",
                                  end.Subtract(start).TotalSeconds, totalPoints);
            }
        }
コード例 #11
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(new LcmsWarpAlignmentOptions());
            var isosFilterOptions = new DeconToolsIsosFilterOptions();

            var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1, isosFilterOptions);
            var aligneeMs  = UmcLoaderFactory.LoadMsFeatureData(path2, isosFilterOptions);
            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, false);
            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);
        }
コード例 #12
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"));
        }
コード例 #13
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(new LcmsWarpAlignmentOptions());
            var isosFilterOptions = new DeconToolsIsosFilterOptions();

            var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1, isosFilterOptions);
            var aligneeMs  = UmcLoaderFactory.LoadMsFeatureData(path2, isosFilterOptions);
            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);
            }
        }
コード例 #14
0
        public string CreateImage(PlotModel model)
        {
            var exporter = new SvgExporter();

            return(exporter.ExportToString(model));
        }