如何在散点图中添加线条? (Java,jmathplot)

时间:2012-07-06 08:53:22

标签: java scatter-plot

使用此代码,我可以绘制散点图。

import javax.swing.*;
import org.math.plot.*;
public class ScatterPlotExample {

public static void main(String[] args) {

    double[] x = new double[] { 60 };
    double[] y = new double[] { 50 };

    // create your PlotPanel (you can use it as a JPanel)
    Plot2DPanel plot = new Plot2DPanel();

    // add a line plot to the PlotPanel

    plot.addScatterPlot("teeeeest", x, y);


    // put the PlotPanel in a JFrame, as a JPanel
    JFrame frame = new JFrame("a plot panel");
    frame.setSize(600, 600);
    frame.setContentPane(plot);
    frame.setVisible(true);

}

}

两个问题:

如何使轴的范围从1到100?
如何在x = 0.4和y = 0.7?

的水平和垂直线上绘制该散点图

谢谢!

1 个答案:

答案 0 :(得分:1)

  • 设置X轴范围:

    plot.setFixedBounds(0,1,100) - > (其中0表示X,1表示Y)

  • 在Y = 49.5处添加水平线:

    plot.addPlotable(new Line(Color.red, new double[]{plot.plotCanvas.base.getMinBounds()[0],49.5}, new double[]{plot.plotCanvas.base.getMaxBounds()[0],49.5}));