2012-07-06 89 views
0

使用此代碼我可以繪製散點圖。如何將一條線添加到散點圖? (Java,jmathplot)

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
  • 設置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}));

相關問題