Repository navigation
Expand file tree
/
Copy pathExampleTimeAxis.cs
More file actions
106 lines (93 loc) · 3.4 KB
/
Copy pathExampleTimeAxis.cs
File metadata and controls
106 lines (93 loc) · 3.4 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
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MatplotlibCS;
using MatplotlibCS.PlotItems;
namespace Examples.Plot2D
{
class ExampleTimeAxis : IExample
{
/// <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
}
}
}