Skip to content

Commit fe98d89

Browse files
http://stackoverflow.com/questions/11358974/how-to-add-a-line-to-a-scatter-plot-java-jmathplot
1 parent fef8499 commit fe98d89

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package stackoverflow.how_to_add_a_line_to_a_scatter_plot_java_jmathplot;
2+
3+
import java.awt.Color;
4+
import javax.swing.*;
5+
import org.math.plot.*;
6+
import org.math.plot.plotObjects.Line;
7+
8+
public class ScatterPlotExample {
9+
10+
public static void main(String[] args) {
11+
12+
double[] x = new double[]{60};
13+
double[] y = new double[]{50};
14+
15+
// create your PlotPanel (you can use it as a JPanel)
16+
Plot2DPanel plot = new Plot2DPanel();
17+
18+
// add a line plot to the PlotPanel
19+
20+
plot.addScatterPlot("teeeeest", x, y);
21+
22+
// put the PlotPanel in a JFrame, as a JPanel
23+
JFrame frame = new JFrame("a plot panel");
24+
frame.setSize(600, 600);
25+
frame.setContentPane(plot);
26+
frame.setVisible(true);
27+
28+
makeAxis1to100(plot);
29+
drawHorizontalLine(plot);
30+
}
31+
32+
public static void makeAxis1to100(PlotPanel plot) {
33+
plot.setFixedBounds(0, 1, 100);
34+
}
35+
36+
public static void drawHorizontalLine(PlotPanel plot) {
37+
plot.addPlotable(new Line(Color.red, new double[]{plot.plotCanvas.base.getMinBounds()[0],49.5},new double[]{plot.plotCanvas.base.getMaxBounds()[0],49.5}));
38+
}
39+
}

0 commit comments

Comments
 (0)