Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
94 lines (80 loc) · 2.39 KB
/
Copy pathProgram.cs
File metadata and controls
94 lines (80 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MatplotlibCS;
namespace Examples
{
/// <summary>
/// Sample programm which creates several charts and save them in png
/// </summary>
class Program
{
/// <summary>
/// Path to python.exe, must be initialized in Main
/// </summary>
private static string _pythonExePath;
/// <summary>
/// Path to dasPlot.py, script which finally builds plots
/// </summary>
private static string _dasPlotPyPath;
static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("You must specify path to python.exe and to dasPlot.py in command line arguments");
Console.ReadKey();
return;
}
_pythonExePath = args[0];
_dasPlotPyPath = args[1];
ExampleSin();
}
/// <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
}
}
}