Skip to content

Commit 6e59307

Browse files
author
richetyann
committed
1 parent 632a1ff commit 6e59307

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package examples;
2+
3+
import java.applet.Applet;
4+
import java.awt.Dimension;
5+
import java.awt.GridLayout;
6+
import org.math.plot.*;
7+
8+
/**
9+
* Copyright : BSD License
10+
* @author Yann RICHET
11+
*/
12+
public class TestApplet extends Applet {
13+
14+
@Override
15+
public void init() {
16+
// Data definition
17+
int n = 10;
18+
double[][] datas1 = new double[n][3];
19+
double[][] datas2 = new double[n][3];
20+
for (int i = 0; i < n; i++) {
21+
for (int j = 0; j < 3; j++) {
22+
datas1[i][j] = Math.random();
23+
datas2[i][j] = Math.random();
24+
}
25+
}
26+
27+
// PlotPanel construction
28+
Plot3DPanel plotpanel = new Plot3DPanel();
29+
plotpanel.addLegend("SOUTH");
30+
31+
// Data plots addition
32+
plotpanel.addScatterPlot("datas1", datas1);
33+
plotpanel.addBarPlot("datas2", datas2);
34+
35+
plotpanel.setSize(600, 600);
36+
plotpanel.setPreferredSize(new Dimension(600, 600));
37+
38+
// include plot in applet
39+
//setLayout(new GridLayout(1,1));
40+
setSize(600, 600);
41+
setPreferredSize(new Dimension(600, 600));
42+
43+
add(plotpanel);
44+
}
45+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package stackoverflow.how_to_set_axis_location_in_jmathplot;
2+
3+
import javax.swing.*;
4+
import org.math.plot.*;
5+
import org.math.plot.plotObjects.Base;
6+
7+
public class Answer {
8+
9+
public static void main(String[] args) {
10+
11+
double[] x = new double[]{60};
12+
double[] y = new double[]{50};
13+
14+
// create your PlotPanel (you can use it as a JPanel)
15+
Plot2DPanel plot = new Plot2DPanel();
16+
17+
// add a line plot to the PlotPanel
18+
19+
plot.addScatterPlot("teeeeest", x, y);
20+
21+
// put the PlotPanel in a JFrame, as a JPanel
22+
JFrame frame = new JFrame("a plot panel");
23+
frame.setSize(600, 600);
24+
frame.setContentPane(plot);
25+
frame.setVisible(true);
26+
27+
setAxisCenter(plot);
28+
}
29+
30+
public static void setAxisCenter(PlotPanel plot) {
31+
plot.plotCanvas.base = new CenteredBase(new double[]{50,50},new double[]{100,100},new String[] { "lin", "lin" });
32+
}
33+
34+
public static class CenteredBase extends Base {
35+
public CenteredBase(double[] Xmi, double[] Xma, String[] scales) {
36+
super(Xmi, Xma, scales);
37+
centerCoords();
38+
}
39+
40+
private void centerCoords() {
41+
baseCoords = new double[dimension + 1][];
42+
for (int i = 0; i < baseCoords.length; i++) {
43+
baseCoords[i] = new double[]{50,50};
44+
if (i > 0)
45+
baseCoords[i][i - 1] = 100;
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)