forked from yannrichet/jmathplot
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLinePlot.java
More file actions
114 lines (85 loc) · 2.83 KB
/
LinePlot.java
File metadata and controls
114 lines (85 loc) · 2.83 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
107
108
109
110
111
112
113
114
package org.math.plot.plots;
import java.awt.*;
import javax.swing.*;
import org.math.plot.*;
import org.math.plot.render.*;
public class LinePlot extends ScatterPlot {
public boolean draw_dot = false;
public LinePlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
super(n, c, _pattern, _XY);
}
public LinePlot(String n, Color[] c, boolean[][] _pattern, double[][] _XY) {
super(n, c, _pattern, _XY);
}
public LinePlot(String n, Color c, int _type, int _radius, double[][] _XY) {
super(n, c, _type, _radius, _XY);
}
public LinePlot(String n, Color[] c, int _type, int _radius, double[][] _XY) {
super(n, c, _type, _radius, _XY);
}
public LinePlot(String n, Color c, double[][] _XY) {
super(n, c, _XY);
}
public LinePlot(String n, Color[] c, double[][] _XY) {
super(n, c, _XY);
}
public void plot(AbstractDrawer draw, Color[] c) {
if (!visible)
return;
if (draw_dot)
super.plot(draw, c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length - 1; i++) {
if (c.length == 1) {
draw.setColor(c[0]);
}
else {
draw.setGradient(XY[i], c[i], XY[i + 1], c[i + 1]);
}
draw.drawLine(XY[i], XY[i + 1]);
}
}
public static void main(String[] args) {
Plot2DPanel p2 = new Plot2DPanel();
double[][] XYZ = new double[100][2];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = 2*Math.PI*(double)j/XYZ.length;
XYZ[j][1] = Math.sin(XYZ[j][0]);
}
p2.addLinePlot("sin" , XYZ);
p2.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Plot3DPanel p = new Plot3DPanel();
XYZ = new double[100][3];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = 2*Math.PI*(double)j/XYZ.length;
XYZ[j][1] = Math.sin(XYZ[j][0]);
XYZ[j][2] = Math.sin(XYZ[j][0])*Math.cos(XYZ[j][1]);
}
p.addLinePlot("toto" , XYZ);
p.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Color[] c = new Color[100];
p2 = new Plot2DPanel();
XYZ = new double[100][2];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = 2*Math.PI*(double)j/XYZ.length;
XYZ[j][1] = Math.sin(XYZ[j][0]);
c[j] = new Color((int)(Math.random() * 0x1000000));
}
p2.addLinePlot("sin", c, XYZ);
p2.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p = new Plot3DPanel();
XYZ = new double[100][3];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = 2*Math.PI*(double)j/XYZ.length;
XYZ[j][1] = Math.sin(XYZ[j][0]);
XYZ[j][2] = Math.sin(XYZ[j][0])*Math.cos(XYZ[j][1]);
c[j] = new Color((int)(Math.random() * 0x1000000));
}
p.addLinePlot("toto", c, XYZ);
p.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}