-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGnuPlot.java
More file actions
65 lines (56 loc) · 1.8 KB
/
GnuPlot.java
File metadata and controls
65 lines (56 loc) · 1.8 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
import org.leores.plot.JGnuplot;
import org.leores.util.data.DataTableSet;
import java.util.ArrayList;
/**
* Created by niklas on 02.03.17.
*/
public class GnuPlot {
public static void plot2d(ArrayList<Double> x, ArrayList<Double> y, String name) {
plot2d(toArray(x), toArray(y), name);
}
public static void plot2d(double[] x, double[] y, String name) {
JGnuplot jg = new JGnuplot() {
{
terminal = "pngcairo enhanced dashed";
output = name + ".png";
}
};
JGnuplot.Plot plot = new JGnuplot.Plot("") {
{
xlabel = "x";
ylabel = "y";
}
};
DataTableSet dts = plot.addNewDataTableSet("2D Plot");
dts.addNewDataTable("", x, y);
jg.execute(plot, jg.plot2d);
}
public static void plot3d(ArrayList<Double> x, ArrayList<Double> y, ArrayList<Double> z, String name) {
plot3d(toArray(x), toArray(y), toArray(z), name);
}
public static void plot3d(double[] x, double[] y, double[] z, String name) {
JGnuplot jg = new JGnuplot() {
{
terminal = "pngcairo enhanced dashed";
output = name + ".png";
}
};
JGnuplot.Plot plot = new JGnuplot.Plot("") {
{
xlabel = "x";
ylabel = "y";
zlabel = "z";
}
};
DataTableSet dts = plot.addNewDataTableSet("3D Plot");
dts.addNewDataTable("", x, y, z);
jg.execute(plot, jg.plot3d);
}
public static double[] toArray(ArrayList<Double> list) {
double[] array = new double[list.size()];
for (int i = 0; i < list.size(); i++) {
array[i] = list.get(i);
}
return array;
}
}