Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();


            if (!Directory.Exists(Environment.CurrentDirectory + @"\python.3.6.0"))
            {
                //Directory.CreateDirectory(Environment.CurrentDirectory + @"\python2.2.7.18");
                System.IO.Compression.ZipFile.ExtractToDirectory(Environment.CurrentDirectory + @"\python.3.6.0.zip",
                                                                 Environment.CurrentDirectory);
            }
            string pyth = Environment.CurrentDirectory + @"\python.3.6.0\tools";

            Environment.SetEnvironmentVariable("PATH", pyth, EnvironmentVariableTarget.Process);
            PythonEngine.PythonHome = pyth;


            Console.WriteLine(PythonEngine.BuildInfo);
            Console.WriteLine(PythonEngine.IsInitialized);
            Console.WriteLine(PythonEngine.ProgramName);
            Console.WriteLine(PythonEngine.PythonHome);
            Console.WriteLine(PythonEngine.PythonPath);

            Console.WriteLine(Runtime.PythonDLL);
            PythonEngine.Initialize();

            numpy = new Python.Runtime.Numpy();

            Console.WriteLine(Environment.GetEnvironmentVariable("TEMP"));
        }
Esempio n. 2
0
        public static byte[] SaveFigureToArray(PyObject fig, int dpi = 200, string format = "png")
        {
            if (fig.GetPythonType().Handle != PltFigureType)
            {
                throw new Exception("object is not a matplotlib Figure");
            }

            dynamic _np = np;
            //buf = io.BytesIO()
            dynamic buf = BytesIO.Invoke();

            //fig.savefig(buf, dpi=__dpi__, format='png')
            fig.InvokeMethod("savefig", new PyTuple(new PyObject[] { buf }), Py.kw("dpi", dpi, "format", format));
            var buf_out = _np.array(buf.getbuffer(), Py.kw("dtype", Numpy.GetNumpyDataType(typeof(byte))));
            var arr     = Numpy.ToArray(buf_out);

            return((byte[])arr);
        }