Ejemplo n.º 1
0
        /// <summary>
        /// Chart of sin
        /// </summary>
        static void ExampleSin()
        {
            #region create test data

            const int    N = 100;
            var          X = new double[N];
            var          Y = new double[N];
            var          x = 0.0;
            const double h = 2 * Math.PI / N;
            for (var i = 0; i < N; i++)
            {
                var y = Math.Sin(x);
                X[i] = x;
                Y[i] = y;
                x   += h;
            }

            #endregion

            #region create plot

            // init engine with right paths
            var dasPlot = new MatplotlibCS.MatplotlibCS(_pythonExePath, _dasPlotPyPath);

            var figure = new Figure(1, 1)
            {
                FileName      = "ExampleSin.png",
                OnlySaveImage = true,
                Subplots      =
                {
                    new Axes(1, "The X axis", "The Y axis")
                    {
                        Title     = "ExampleSin",
                        PlotItems =
                        {
                            new Line2D("Sin")
                            {
                                X = X.ToList(),
                                Y = Y.ToList()
                            }
                        }
                    }
                }
            };

            dasPlot.BuildFigure(figure);

            #endregion
        }
Ejemplo n.º 2
0
        public void Draw(List <Axes> plots)
        {
            // 由于我们在外部启动Python服务,这两个参数传空字符串就可以了
            var matplotlibCs = new MatplotlibCS.MatplotlibCS("", "");

            var figure = new Figure(1, 1)
            {
                FileName      = $"/mnt/e/Temp/result{DateTime.Now:ddHHmmss}.png",
                OnlySaveImage = true,
                DPI           = 150,
                Subplots      = plots
            };
            var t = matplotlibCs.BuildFigure(figure);

            t.Wait();
        }
Ejemplo n.º 3
0
        private void Plot(NDArray x, NDArray y)
        {
            var matplotlibCs = new MatplotlibCS.MatplotlibCS("python", @"D:\Projects\MatplotlibCS\MatplotlibCS\Python\matplotlib_cs.py");

            var items = new List <PlotItem>();

            for (int i = 0; i < x.size; i++)
            {
                items.Add(new Point2D($"P{i}", x.Data <double>()[i], x.Data <double>()[i])
                {
                    MarkerFaceColor = Color.Black,
                    MarkerSize      = 3
                });
            }

            var figure = new Figure(1, 1)
            {
                FileName      = "regression.png",
                OnlySaveImage = true,
                DPI           = 150,
                Subplots      =
                {
                    new Axes(1, "X axis", "Y axis")
                    {
                        Title = "Regression Test",
                        Grid  = new Grid()
                        {
                            XLim = new double[] { 0,1.2 },
                            YLim = new double[] { -2,      12 }
                        },
                        PlotItems = items
                    }
                }
            };

            var t = matplotlibCs.BuildFigure(figure);

            t.Wait();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Chart of sin
        /// </summary>
        public void Run(string pythonExePath, string dasPlotPyPath)
        {
            #region create test data

            const int N   = 1000;
            var       X   = new double[N];
            var       rnd = new Random();
            for (var i = 0; i < N; i++)
            {
                X[i] = (rnd.NextDouble() - 0.5) * 10.0;
            }

            #endregion

            #region create plot

            // init engine with right paths
            var matplotlibCs = new MatplotlibCS.MatplotlibCS(pythonExePath, dasPlotPyPath);

            var figure = new Figure(2, 2)
            {
                FileName      = "ExampleHistogram.png",
                OnlySaveImage = true,
                DPI           = 150,
                Subplots      =
                {
                    new Axes(1, "The X axis", "The Y axis")
                    {
                        Title      = "Hist 1",
                        ShowLegend = false,
                        PlotItems  =
                        {
                            new Histogram("Sin")
                            {
                                Y = X.ToList(),
                            }
                        }
                    },
                    new Axes(2, "The X axis", "The Y axis")
                    {
                        Title     = "Hist 2",
                        PlotItems =
                        {
                            new Histogram("Sin")
                            {
                                Y     = X.ToList(),
                                Color = Color.Black,
                                Alpha = 0.5,
                                Range = new []{                    -1,          1.0 }
                            }
                        }
                    },
                    new Axes(3, "The X axis", "The Y axis")
                    {
                        Title     = "Hist 3",
                        PlotItems =
                        {
                            new Histogram("Sin")
                            {
                                Y           = X.ToList(),
                                Orientation = HistogramOrientation.Horizontal
                            }
                        }
                    },
                    new Axes(4, "The X axis", "The Y axis")
                    {
                        Title     = "Hist 4",
                        PlotItems =
                        {
                            new Histogram("Sin")
                            {
                                Y      = X.ToList(),
                                Bins   = 10,
                                Color  = Color.Red,
                                Alpha  = 0.5,
                                Range  = new [] { -1, 1.0 },
                                Normed = true
                            }
                        }
                    },
                }
            };

            var t = matplotlibCs.BuildFigure(figure);
            t.Wait();

            #endregion
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Chart of sin
        /// </summary>
        public void Run(string pythonExePath, string dasPlotPyPath)
        {
            #region create test data

            const int    N   = 100;
            var          X   = new double[N];
            var          Y1  = new double[N];
            var          Y2  = new double[N];
            var          x   = 0.0;
            const double h   = 2 * Math.PI / N;
            var          rnd = new Random();
            for (var i = 0; i < N; i++)
            {
                var y = Math.Sin(x);
                X[i]  = x;
                Y1[i] = y;

                y     = Math.Sin(2 * x);
                Y2[i] = y + rnd.NextDouble() / 10.0;

                x += h;
            }

            #endregion

            #region create plot

            // init engine with right paths
            var matplotlibCs = new MatplotlibCS.MatplotlibCS(pythonExePath, dasPlotPyPath);

            var figure = new Figure(1, 1)
            {
                FileName      = "ExampleSin.png",
                OnlySaveImage = true,
                DPI           = 150,
                Subplots      =
                {
                    new Axes(1,                    "The X axis",            "The Y axis")
                    {
                        Title        = "Sin(x), Sin(2x), VLines, HLines, Annotations",
                        LegendBorder = false,
                        Grid         = new Grid()
                        {
                            MinorAlpha  = 0.2,
                            MajorAlpha  = 1.0,
                            XMajorTicks = new[] { 0.0,                 7.6,               0.5,  1.75 },
                            YMajorTicks = new[] { -1,                  2.5,              0.25, 0.125 },
                            XMinorTicks = new[] { 0.0,                7.25,              0.25, 1.125 },
                            YMinorTicks = new[] { -1,                  2.5,             0.125, 1.025 }
                        },
                        PlotItems =
                        {
                            new Line2D("Sin")
                            {
                                X         = X.Cast <object>().ToList(),
                                Y         = Y1.ToList(),
                                LineStyle = LineStyle.Dashed
                            },

                            new Line2D("Sin 2x")
                            {
                                X          = X.Cast <object>().ToList(),
                                Y          = Y2.ToList(),
                                LineStyle  = LineStyle.Solid,
                                LineWidth  = 0.5f,
                                Color      = "r",
                                Markevery  = 5,
                                MarkerSize = 10,
                                Marker     = Marker.Circle,
                                ShowLegend = false
                            },

                            new Text("ant1",       "Text annotation",                     4.5,                     0.76)
                            {
                                FontSize = 17
                            },

                            new Annotation("ant2", "Arrow text annotation",               0.5,-0.7, 3, 0)
                            {
                                Color      = "#44ff88",
                                ArrowStyle = ArrowStyle.Both,
                                LineWidth  = 3,
                            },

                            new Vline("vert line", new object[]{                                     3.0 },                   -1, 1),
                            new Hline("hrzt line", new[]{ 0.1,                        0.25, 0.375 },                    0, 5)
                            {
                                LineStyle = LineStyle.Dashed,Color = Color.Magenta
                            }
                        }
                    }
                }
            };

            var t = matplotlibCs.BuildFigure(figure);
            t.Wait();

            #endregion
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Chart of sin
        /// </summary>
        public void Run(string pythonExePath, string dasPlotPyPath)
        {
            #region create test data

            const int    N   = 10;
            var          X   = new double[N];
            var          Y1  = new double[N];
            var          Y2  = new double[N];
            var          x   = 0.0;
            const double h   = 2 * Math.PI / N;
            var          rnd = new Random();
            for (var i = 0; i < N; i++)
            {
                var y = Math.Sin(x);
                X[i]  = x;
                Y1[i] = y;

                y     = Math.Sin(2 * x);
                Y2[i] = y + rnd.NextDouble() / 10.0;

                x += h;
            }

            #endregion

            #region create plot

            // init engine with right paths
            var matplotlibCs = new MatplotlibCS.MatplotlibCS(pythonExePath, dasPlotPyPath);

            var timeTicks = new List <DateTime>();
            timeTicks.Add(DateTime.Now);

            var xMajorTicks = new List <double>();
            xMajorTicks.Add(0);
            for (var i = 1; i < N; i++)
            {
                xMajorTicks.Add(i);
                timeTicks.Add(timeTicks[i - 1] + new TimeSpan(0, rnd.Next(1, 10), 0, 0));
            }

            var figure = new Figure(1, 1)
            {
                FileName      = "ExampleTimeAxis.png",
                OnlySaveImage = true,
                DPI           = 150,
                Subplots      =
                {
                    new Axes(1,             "Time", "Value")
                    {
                        Title        = "Time Axis Example",
                        LegendBorder = false,
                        Grid         = new Grid()
                        {
                            MinorAlpha      = 0.2,
                            MajorAlpha      = 1.0,
                            XTimeTicks      = timeTicks.Cast <object>().ToList(),
                            TimeTickFormat  = TimeTickFormat.HHMMSS,
                            RegularTimeAxis = true,
                            YMajorTicks     = new[] { -1, 2.5,             0.25, 0.125 },
                            XMinorTicks     = new[] { 0.0, 7.25,           0.25, 1.125 },
                            YMinorTicks     = new[] { -1, 2.5,            0.125, 1.025 },
                            XTickFontSize   = 8,
                            XTickRotation   = 30
                        },
                        PlotItems =
                        {
                            new Line2D("Data")
                            {
                                //X = timeTicks.Cast<object>().ToList(),
                                X          = xMajorTicks.Cast <object>().ToList(),
                                Y          = Y1.ToList(),
                                LineStyle  = LineStyle.Dashed,
                                Marker     = Marker.Circle,
                                MarkerSize = 5
                            },
                            //new Vline("vl", new object[] {DateTime.Now.AddHours(10)},-1,1),
                            new Vline("vl", new object[]{                              5 },              -1, 1)
                        }
                    }
                }
            };

            var t = matplotlibCs.BuildFigure(figure);
            t.Wait();

            #endregion
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Chart of sin
        /// </summary>
        public void Run(string pythonExePath, string dasPlotPyPath)
        {
            // init engine with right paths
            var matplotlibCs = new MatplotlibCS.MatplotlibCS(pythonExePath, dasPlotPyPath);

            var figure = new Figure(1, 1)
            {
                FileName      = "ExampleVisibility1.png",
                OnlySaveImage = true,
                DPI           = 150,
                Subplots      =
                {
                    new Axes(1,                 "The X axis", "The Y axis")
                    {
                        Title     = "Visibility",
                        PlotItems =
                        {
                            new Line2D("Line 1")
                            {
                                X = new List <object>()
                                {
                                    -1,              1
                                },
                                Y = new List <double>()
                                {
                                    -1,              1
                                },
                                LineStyle = LineStyle.Dashed,
                                Color     = Color.Blue
                            },
                            new Line2D("Line 2")
                            {
                                X = new List <object>()
                                {
                                    -1,              1
                                },
                                Y = new List <double>()
                                {
                                    -2,              2
                                },
                                LineStyle = LineStyle.Solid,
                                Color     = Color.Red,
                                IsVisible = false // set this line invisible for first image
                            },
                            new Point2D("plus",          0.5, -0.5)
                            {
                                Marker     = Marker.Circle,
                                MarkerSize = 10,
                                Color      = Color.Green,
                                LineWidth  = 2
                            },
                        }
                    }
                }
            };

            var t = matplotlibCs.BuildFigure(figure);

            t.Wait();

            figure.Subplots[0]["Line 2"].IsVisible = true; // now turn one line2 vivibility and build the second image with new name
            figure.FileName = "ExampleVisibility2.png";
            t = matplotlibCs.BuildFigure(figure);
            t.Wait();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Chart of sin
        /// </summary>
        public static void Run(string pythonExePath, string dasPlotPyPath)
        {
            // init engine with right paths
            var matplotlibCs = new MatplotlibCS.MatplotlibCS(pythonExePath, dasPlotPyPath);

            var figure = new Figure(1, 1)
            {
                FileName      = "ExamplePoint2D.png",
                OnlySaveImage = true,
                DPI           = 150,
                Subplots      =
                {
                    new Axes(1,                    "The X axis", "The Y axis")
                    {
                        Title = "2D points",
                        Grid  = new Grid()
                        {
                            XLim = new double[] { -5,      15 },
                            YLim = new double[] { -5,                         15 }
                        },
                        PlotItems =
                        {
                            new Point2D("Point 1",            0, 0)
                            {
                                MarkerEdgeColor = Color.Black,
                                MarkerFaceColor = Color.Cyan,
                                MarkerSize      = 15,
                                MarkerEdgeWidth = 2,
                            },
                            new Point2D("Point 2",           10, 10)
                            {
                                Color           = Color.Red,
                                MarkerSize      = 15,
                                MarkerEdgeWidth = 3,
                                Marker          = Marker.Vline
                            },
                            new Line2D("Line 1")
                            {
                                X = new List <object>()
                                {
                                    -2,                                 8.0
                                },
                                Y = new List <double>()
                                {
                                    0,                                 10.0
                                },
                                Color           = Color.Green,
                                MarkerEdgeColor = Color.Blue,
                                MarkerFaceColor = Color.None,
                                MarkerEdgeWidth = 3,
                                Marker          = Marker.Circle,
                                MarkerSize      = 10
                            }
                        }
                    }
                }
            };

            var t = matplotlibCs.BuildFigure(figure);

            t.Wait();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Chart of sin
        /// </summary>
        public static void Run(string pythonExePath, string dasPlotPyPath)
        {
            #region create test data

            var X = new double[2] {
                -1, 1
            };
            var Y = new double[2] {
                -1, 1
            };

            #endregion

            #region create plot

            // init engine with right paths
            var matplotlibCs = new MatplotlibCS.MatplotlibCS(pythonExePath, dasPlotPyPath);

            var figure = new Figure(1, 1)
            {
                FileName      = "ExampleArc.png",
                OnlySaveImage = true,
                Width         = 1080,
                DPI           = 150,
                Subplots      =
                {
                    new Axes(1,                    "The X axis", "The Y axis")
                    {
                        Title          = "Arc, Annotations",
                        LegendLocation = LegendLocation.LowerLeft,
                        Grid           = new Grid()
                        {
                            MinorAlpha = 0.2,
                            MajorAlpha = 1.0,
                        },
                        PlotItems =
                        {
                            new Line2D("45")
                            {
                                X = new List <object>()
                                {
                                    -1,                 1
                                },
                                Y = new List <double>()
                                {
                                    -1,                 1
                                },
                                Color = Color.Blue
                            },
                            new Line2D("90")
                            {
                                X = new List <object>()
                                {
                                    0,                 0
                                },
                                Y = new List <double>()
                                {
                                    -1,                 1
                                },
                                Color = Color.Magenta
                            },
                            new Line2D("145")
                            {
                                X = new List <object>()
                                {
                                    -1,                 1
                                },
                                Y = new List <double>()
                                {
                                    1,                 -1
                                },
                                Color = Color.Green
                            },

                            new Arc("45 arc",                 0,    0, 0.5,   0.5,     0, 0, 45)
                            {
                                Color = Color.Blue
                            },
                            new Arc("90 arc",                 0,    0, 0.6,   0.6,     0, 0, 90)
                            {
                                Color = Color.Magenta
                            },
                            new Arc("135 arc",                0,    0, 0.7,   0.7,     0, 0, 135)
                            {
                                Color = Color.Green
                            },

                            new Text("ant1",       "45",          0.1,                     0.04)
                            {
                                Alpha = 0.4
                            },
                            new Annotation("ant2", "90",          0.2, 0.6,  0.11,                     0.26)
                            {
                                Alpha = 0.5
                            },
                            new Annotation("ant3", "135",        -0.2, 0.6, -0.08, 0.32),

                            new Hline("0",                    0,   -1,1)
                            {
                                LineStyle = LineStyle.Solid,Color = Color.Black
                            }
                        }
                    }
                }
            };

            var t = matplotlibCs.BuildFigure(figure);
            t.Wait();

            #endregion
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            string       path   = "C:\\Users\\King\\Desktop\\EnvisBackUps\\2018-04.cea";
            MyDataReader reader = new MyDataReader();

            reader.LoadCea(path);

            List <UniArchiveBase> result = new List <UniArchiveBase>();

            for (int i = 0; i < 10000; i++)
            {
                result.Add(reader.LoadNext());
            }

            // values restricted to one day 1.4.2018
            var values  = reader.values.Where(i => i.Key.Day == 1 && i.Key.Month == 4).Select(i => double.Parse(i.Value)).ToList(); // 8644 values for each 10 seconds
            var values2 = result.Select(i => double.Parse(i.GetMemberValue("I_avg_3I").ToString())).Take(8644).ToList();
            var values3 = result.Select(i => double.Parse(i.GetMemberValue("U_avg_U3").ToString())).Take(8644).ToList();

            var times2 = reader.values.Where(i => i.Key.Day == 1 && i.Key.Month == 4).Select(i => i.Key.Hour as object).ToList(); // 8644 values for each 10 seconds

            double[] X    = new double[] { -10, -8.5, -2, 1, 6, 9, 10, 14, 15, 19 };
            double[] Y    = new double[] { -4, 6.5, -2, 3, -8, -5, 11, 4, -5, 10 };
            var      osaX = X.Select(i => i as object).ToList();

            string tempfolder = System.IO.Path.GetTempPath();

            tempfolder = "C:\\Users\\King\\Documents\\BP\\";

            string pythonExe = "C:\\Users\\King\\AppData\\Local\\Programs\\Python\\Python37\\python.exe";
            //string plotPath = "C:\\Users\\King\\source\\repos\\MatplotlibCS\\MatplotlibCS\\Python\\matplotlib_cs.py";
            string plotPath         = "C:\\Users\\King\\source\\repos\\MatplotlibTest\\MatplotlibTest\\MatplotlibCS\\matplotlib_cs.py";
            var    matplotLibEngine = new MatplotlibCS.MatplotlibCS(pythonExe, plotPath);

            var figure = new Figure(3, 1)
            {
                FileName      = "P_avg_3P_C_fromMatplotLibCS.pdf",
                OnlySaveImage = true,
                DPI           = 150,
                Width         = 1920,
                Height        = 1080,
                Subplots      =
                {
                    new Axes(1,                                     "dayhours",                            "P(W)")
                    {
                        Title          = "1.4.2018",
                        LegendLocation = LegendLocation.UpperLeft,
                        Grid           = new Grid()
                        {
                            MinorAlpha  = 0.2,
                            MajorAlpha  = 1.0,
                            XMajorTicks = new[] { 0.0,                                               24.0,                  1.0 }, //min, max, step
                            YMajorTicks = new[] { 0.0,                                             4200.0,                600.0 },
                            //XMinorTicks = new[] {0.0, 7.25, 0.25},
                            //YMinorTicks = new[] {-1, 2.5, 0.125}
                        },
                        PlotItems =
                        {
                            new Line2D("řada P-avg-3P-C")
                            {
                                X         = times2,
                                Y         = values,
                                LineStyle = LineStyle.Solid,
                                Color     = Color.Blue,
                            },

                            new Annotation("Arrow text annotation", "Arrow text annotation example",                                      14.0, 1000.0, 22.0, 1500.0)
                            {
                                Color = Color.Blue
                            },

                            //new Vline("vert line", new[] {3.0 as object}, -1, 1),
                            //new Hline("hrzt line", new[] {0.1, 0.25, 0.375}, 0, 5) {LineStyle = LineStyle.Dashed, Color = Color.Magenta}
                        }
                    },
                    new Axes(2,                                     "dayhours",                            "I(A)")
                    {
                        Title          = "",
                        LegendLocation = LegendLocation.UpperLeft,
                        Grid           = new Grid()
                        {
                            MinorAlpha  = 0.2,
                            MajorAlpha  = 1.0,
                            XMajorTicks = new[] { 0.0,                                               24.0,                  1.0 }, //min, max, step
                            YMajorTicks = new[] { 0.0,                                               19.0,                  5.0 },
                            //XMinorTicks = new[] {0.0, 7.25, 0.25},
                            //YMinorTicks = new[] {-1, 2.5, 0.125}
                        },
                        PlotItems =
                        {
                            new Line2D("řada I-avg-3I")
                            {
                                X         = times2,
                                Y         = values2,
                                LineStyle = LineStyle.Solid,
                                Color     = Color.Yellow,
                                LineWidth = 2.0F,
                            },

                            new Text("Named annotation",            "2px solid line - comment text 15pt",                                      11.0, 9.0)
                            {
                                FontSize = 15
                            },

                            //new Vline("vert line", new[] {3.0 as object}, -1, 1),
                            //new Hline("hrzt line", new[] {0.1, 0.25, 0.375}, 0, 5) {LineStyle = LineStyle.Dashed, Color = Color.Magenta}
                        }
                    },
                    new Axes(3,                                     "dayhours",                            "U(V)")
                    {
                        Title          = "",
                        LegendLocation = LegendLocation.UpperLeft,
                        Grid           = new Grid()
                        {
                            MinorAlpha  = 0.2,
                            MajorAlpha  = 1.0,
                            XMajorTicks = new[] { 0.0,                                               24.0,                  1.0 }, //min, max, step
                            YMajorTicks = new[] { 220.0,                                            250.0,                  5.0 },
                            //XMinorTicks = new[] {0.0, 7.25, 0.25},
                            //YMinorTicks = new[] {-1, 2.5, 0.125}
                        },
                        PlotItems =
                        {
                            new Line2D("řada U-avg-U3")
                            {
                                X         = times2,
                                Y         = values3,
                                LineStyle = LineStyle.Solid,
                                Color     = Color.Green,
                            },
                            new Text("Named annotation",            "horizontal and vertical lines - 2px",                                      11.0, 245.0)
                            {
                                FontSize = 13
                            },
                            new Vline("vertical line",              new[]{                                               3.5 as object },        220.0, 250.0)
                            {
                                LineStyle = LineStyle.Solid,        Color = Color.Magenta,                 LineWidth = 2F
                            },
                            new Hline("hrzt line",                  new[]{                                                       232.0 },            0, 23.0)
                            {
                                LineStyle = LineStyle.Dashed,       Color = Color.Magenta
                            }
                        }
                    }
                }
            };

            //act
            var t = matplotLibEngine.BuildFigure(figure);

            t.Wait();
        }