/**
* Simon George and Glen Cowan
* Royal Holloway, University of London
* 1 October, 2001
* last updated 27 Nov 03 SG: set JFrame to dispose on close so the program
* finishes when all graph windows are closed.
*
* Compile with: javac -classpath $PTII SimplePlot.java
* where environment variable PTII points to the base directory of ptplot.
*/
import ptolemy.plot.*;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JFrame;
import javax.swing.WindowConstants; // for DISPOSE_ON_CLOSE
/**
* Class to simplify plotting of histograms and curves with Ptplot
* Uses the Ptolemy Ptplot package, by extending the Plot class.
* All methods of Plot can therefore still be used. See
* Plot class documentation
* @author Glen Cowan
* @author Simon George
* @version 1.0 2 Sep 2006
*/
public class SimplePlot extends Plot
{
private JFrame theJFrame;
private int dataset = 0;
/** Constructor
*/
public SimplePlot()
{
theJFrame = new JFrame();
theJFrame.setSize(400, 350); // outer box
setSize(350, 300); // graph window
setButtons(true); // buttons to print, edit, etc.
setMarksStyle("none"); // do not show marks at points
}
/**
* Draw a histogram.
* It is assumed that all bins are of equal size.
* @param name The name to give this histogram in the key
* @param xMin minimum of x-range covered by histogram
* @param xMax maximum of x-range covered by histogram
* @param y array of bin heights; length of array is used to give number of points
*/
public void drawHistogram(String name, double xMin, double xMax, double[] y)
{
double binWidth = (xMax - xMin)/y.length;
this.setBars(binWidth,0.0); // set bars width + offset
this.setConnected(false); // do not join bars with a line
boolean first = true;
for (int i = 0; i