Michael Thomas Flanagan's Java Scientific Library

PlotGraph Class:      Drawing Graphs

     

Last update: 21 February 2011
Main Page of Michael Thomas Flanagan Java Scientific Library

This class contains methods for plotting one or several curves on the same abscissa (horizontal axis, x-axis) and ordinate (vertical axis, y-axis) axes and of displaying the graph in a window. The graph is resized when the window is resized, maximized when the window is maximized and restored when the window is hidden and then restored. This is a subclass of the superclass Plot.

import directives: import flanagan.plot.PlotGraph;
Related classes:

SUMMARY OF CONSTRUCTOR AND METHODS

Constructor Single curve public void PlotGraph(double[][] data) obligatory Class: PlotGraph
Single or Several curves public void PlotGraph(double[] xData, double[] yData)
Set up and
display the graph
Initialise data array public static double[][] data(int nCurves, int nPoints) optional but recommended for multiple curves of different length Class: Plot
public static void setDataFillValue(double dataFillValue) optional Class: Plot
public static double getDataFillvalue() optional Class: Plot
Plot and show graph public void plot() obligatory Class: PlotGraph
Enter graph title public void setGraphTitle(String gTitle) optional but recommended Class: Plot
public void setGraphTitle2(String gTitle2) optional Class: Plot
Enter the abscissa axis (x axis) legend public void setXaxisLegend(String xLeg) optional but recommended Class: Plot
Enter name of the abscissa axis (x axis) units public void setXaxisUnitsName(String xUnits) optional but recommended Class: Plot
Enter the ordinate axis (y axis) legend public void setYaxisLegend(String yLeg) optional but recommended Class: Plot
Enter name of the ordinate axis (y axis) units public void setYaxisUnitsName(String yUnits) optional but recommended Class: Plot
Enter the abscissa axis (x axis) legend public void setXaxisLegend(String xLeg) optional but recommended Class: Plot
Enter error bars public void setErrorBars(int nc, double[] err) optional Class: Plot
Line
options
Reset line options public void setLine(int lineOpt) optional Class: Plot
public void setLine(int[] lineOpt)
Get line options public int[] getLine() optional Class: Plot
Reset interpolation number public void setNiPoints(int niPoints) optional Class: Plot
Get interpolation number public int getNiPoints() optional Class: Plot
Reset dash length public void setDashLength(int dashLength) optional Class: Plot
public void setDashLength(int[] dashLength)
Get dash length public int[] getDashLength() optional Class: Plot
Point
options
Reset point symbol public void setPoint(int pointOpt) optional Class: Plot
public void setPoint(int[] pointOpt)
Get point symbol public int[] getPoint() optional Class: Plot
Reset point size public void setPointSize(int pointSize) optional Class: Plot
public void setPointSize(int[] pointSize)
Get point size public int[] getPointSize() optional Class: Plot
Offset
option
Reset the abscissa axis (x axis) offset option public void setNoXoffset(boolean noXoffset) optional Class: Plot
Get the abscissa axis (x axis) offset option public double getNoXoffset() optional Class: Plot
Reset the ordinate axis (y axis) offset option public void setNoYoffset(boolean noYoffset) optional Class: Plot
Get the ordinate axis (y axis) offset option public double getNoYoffset() optional Class: Plot
Reset the abscissa and ordinate axes offset options public void setNoOffset(boolean noXorYoffset) optional Class: Plot
High and low
values on
each axis
Reset the abscissa axis (x axis) lowest value public void setXlowFac(double xLowFac) optional Class: Plot
Get the abscissa axis (x axis) lowest value factor public double getXlowFac() optional Class: Plot
Reset the ordinate axis (y axis) lowest value public void setYlowFac(double yLowFac) optional Class: Plot
Get the ordinate axis (y axis) lowest value factor public double getYlowFac() optional Class: Plot
Get the minimum value of the abscissa axis (x axis) public double getXmin() optional Class: Plot
Get the maximum value of the abscissa axis (x axis) public double getXmax() optional Class: Plot
Get the minimum value of the ordinate axis (y axis) public double getYmin() optional Class: Plot
Get the maximum value of the ordinate axis (y axis) public double getYmax() optional Class: Plot
Rescale
the graph
Rescale the abscissae (x dimension) public void rescaleX(double xScaleFac) optional Class: PlotGraph
Rescale the ordinates (y dimension) public void rescaleY(double yScaleFac) optional Class: PlotGraph
Reset the abscisa axis (x axis) pixel length public void setXaxisLen(int xLen) optional Class: Plot
Get the abscissa axis (x axis) pixel length public int setXaxisLen() optional Class: Plot
Reset the ordinate axis(y axis) pixel length public void setYaxisLen(int yLen) optional Class: Plot
Get the ordinate axis (y axis) pixel length public int getYaxisLen() optional Class: Plot
Reposition
the graph
Reset the pixel start of the abscissa axis (x axis) public void setXlow(int xLow) optional Class: Plot
Get the pixel start of the abscissa axis (x axis) public int getXlow() optional Class: Plot
Reset the pixel top of the ordinate axis (y axis) public void setYhigh(int yTop) optional Class: Plot
Get the pixel top of the ordinate axis (y axis) public int getYhigh() optional Class: Plot
Window
options
Window closing option public void setCloseChoice(int closeChoice) optional Class: PlotGraph
Get window closing option public int getCloseChoice() optional Class: PlotGraph
Reset height of graph window public void setGraphHeight(int graphHeight) optional Class: PlotGraph
Get height of graph window public int getGraphHeight() optional Class: PlotGraph
Reset width of graph window public void setGraphWidth(int graphWidth) optional Class: PlotGraph
Get width of graph window public int getGraphWidth() optional Class: PlotGraph
Ending the application End the program public void.endProgram() optional Class: PlotGraph

CONSTRUCTORS AND METHODS

CONSTRUCTORS AND PLOT METHOD

CONSTRUCTORS
SINGLE CURVE

public PlotGraph(double[] xData, double[] yData)
Usage:                      PlotGraph pg = new PlotGraph(xData, yData);
Creates a new instance of PlotGraph for plotting a single curve from the the data points contained in the two arrays; xData, containing the abscissa (horizontal axis, x-axis) values, and yData, containing the ordinate (vertical axis, y-axis) values.
The alternate constructor designed primarily for plotting multiple curves, taking as its argument a single two dimensional array, may also be used to plot a single curve, e.g.
public PlotGraph(double[ ][ ] cdata)
Usage:                      PlotGraph pg = new PlotGraph(cdata);
In the case of a single array, and in the above usage, cdata will be a 2 x n two dimensional array of doubles, e.g.
     double[ ][ ] cdata = new double[2][n];
where n is the number of data points.
The abscissa (horizontal) axis values should be stored in cdata[0][0], cdata[0][1], cdata[0][2], cdata[0][3],    . . .    cdata[0][n-1]
The ordinate (verical) axis values should be stored in cdata[1][0], cdata[1][1], cdata[1][2], cdata[1][3],    . . .    cdata[1][n-1]
A method of initialising the data array argument, cdata in the above usage, so that PlotGraph may check that all array elements have been filled is described below; see method PlotGraph.data(nCurves, nPoints).
More than one PlotGraph instance may be created within a single application.
ArrayMaths may be found useful in converting non-double one dimensional arrays into a type acceptable to PlotGraph.

MULTIPLE CURVES
public PlotGraph(double[][] data)
Usage:                      PlotGraph pg = new PlotGraph(cdata);
Creates a new instance of PlotGraph for plotting multiple curves on one graph for the data contained in the two dimensional array of data points, cdata.
The array, cdata, may be created either by calling the special method PlotGraph.data(nCurves, nPoints) or by any of the standard methods of creating a two dimensional array of double, e.g.:
     double[ ][ ] cdata = PlotGraph.data(nCurves, nPoints);
or
     double[ ][ ] cdata = new double[nCurves][nPoints];
where nCurves is the number of curves and nPoints is the number of points in the curve with the maximum number of points. The former is the safer method as it allows PlotGraph to check whether all the array elements have been filled correctly. This becomes important if the length of, i.e. number of data points in, the curves differ. See below for details of PlotGraph.data(nCurves, nPoints).
The array cdata may contain data for one or for several curves. The even numbered rows of cdata should contain the abscissa (horizontal) axis data and the odd numbered rows should contain the ordinate (vertical) axis data, e.g.

The abscissa (horizontal) axis values of the first curve should be stored in:
cdata[0][0], cdata[0][1], cdata[0][2], cdata[0][3],    . . .    cdata[0][nPoints[0]-1]
The ordinate (verical axis) values of the first curve should be stored stored in:
cdata[1][0], cdata[1][1], cdata[1][2], cdata[1][3],    . . .    cdata[1][npoint[0]-1]
The abscissa (horizontal) axis values of the second curve should be stored in:
cdata[2][0], cdata[2][1], cdata[2][2], cdata[2][3],    . . .    cdata[2][nPoints[1]-1]
The ordinate (verical axis) values of the second curve should be stored stored in:
cdata[3][0], cdata[3][1], cdata[3][2], cdata[3][3],    . . .    cdata[3][npoint[1]-1]
. . .
The abscissa (horizontal) axis values of the last curve should be stored in:
cdata[2*nCurves][0], cdata[2*nCurves][1], cdata[2*nCurves][2], cdata[2*nCurves][3],    . . .    cdata[2*nCurves][nPoints[nCurves]-1]
The ordinate (verical axis) values of the last curve should be stored stored in:
cdata[2*nCurves+1][0], cdata[2*nCurves+1][1], cdata[2*nCurves+1][2], cdata[2*nCurves+1][3],    . . .    cdata[2*nCurves+1][npoint[nCurves-1]-1]

where nCurves is the number of curves and nPoints[i] is the number of points in the (i+1)th curve, e.g. i=0 for the first curve. The pairs of rows do not have to be of identical length.
All curves will be scaled as a set so a set of curves should have values of comparable magnitude. It is better to call several instances of PlotGraph if they are of significantly different magnitudes, as more than one PlotGraph instance may be created within a single application.
More than one PlotGraph instance may be created within a single application.
ArrayMaths may be found useful in converting non-double one dimensional arrays into a type acceptable to PlotGraph.

INITIALISE DATA ARRAY
public static double[][] data(int nCurves, int nPoints)
Usage:                      double[ ][ ] cdata = PlotGraph.data(nCurves, nPoints);
This static method initialises the data array needed by PlotGraph. The arguments are the number of curves and the number of points on the curve with the greatest number of points. The data to be plotted is then assigned to the array that has been initialised as above, e.g. cdata in the above example. The array may contain data for one or for several curves. The even numbered rows of cdata should contain the abscissa (horizontal) axis data and the odd numbered rows should contain the ordinate (vertical) axis data, e.g.

The abscissa (horizontal) axis values of the first curve should be stored in:
cdata[0][0], cdata[0][1], cdata[0][2], cdata[0][3],    . . .    cdata[0][nPoints[0]-1]
The ordinate (verical axis) values of the first curve should be stored stored in:
cdata[1][0], cdata[1][1], cdata[1][2], cdata[1][3],    . . .    cdata[1][npoint[0]-1]
The abscissa (horizontal) axis values of the second curve should be stored in:
cdata[2][0], cdata[2][1], cdata[2][2], cdata[2][3],    . . .    cdata[2][nPoints[1]-1]
The ordinate (verical axis) values of the second curve should be stored stored in:
cdata[3][0], cdata[3][1], cdata[3][2], cdata[3][3],    . . .    cdata[3][npoint[1]-1]
. . .
The abscissa (horizontal) axis values of the last curve should be stored in:
cdata[2*nCurves][0], cdata[2*nCurves][1], cdata[2*nCurves][2], cdata[2*nCurves][3],    . . .    cdata[2*nCurves][nPoints[nCurves]-1]
The ordinate (verical axis) values of the last curve should be stored stored in:
cdata[2*nCurves+1][0], cdata[2*nCurves+1][1], cdata[2*nCurves+1][2], cdata[2*nCurves+1][3],    . . .    cdata[2*nCurves+1][npoint[nCurves-1]-1]

where nCurves is the number of curves and nPoints[i] is the number of points in the (i+1)th curve, e.g. i=0 for the first curve. The pairs of rows do not have to be of identical length.
All curves will be scaled as a set so a set of curves should have values of comparable magnitude. It is better to call several instances of PlotGraph if they are of significantly different magnitudes, as more than one PlotGraph instance may be created within a single application.

The method PlotGraph.data(nCurves, nPoints) initially fills all array elements with the value three times ten raised to the power 200 (3x10^200). On invoking the constructor each row of the array cdata, if it contains values 3x10^200, is shortened to eliminate all elements in which both the ordinate and abscissa values are 3x10^200. This allows the user to fill cdata with individual rows of different length without worrying about the unfilled elements. The value 3x10^200 may be changed if this value is inconvenient (see immediately below for method PlotGraph.setDataFillValue(dataFillValue)). Of course the ordinate and abscissa lengths must be the same length for each individual curve.

Initialisation of the form:
                     double[ ][ ] cdata = {{ 1.0, 2.0, 3.0},{1.0, 4.0,9.0},{0.0, 0.5, 1.0,1.5,2.0},{1.1, 2.2, 3.4, 4.4, 5.5}};
also allows PlotGraph to work successfully.

A standard initialisation of the data array, i.e.
                     double[ ][ ] cdata = double[nCurves][nPoints];
may also work but will plot any tailing values of 0.0, 0.0 as if they were real points even when they may simply be the initialisation values, on creation of the array, which have not been overwritten.

CHANGE THE ARRAY FILL VALUE FOR THE METHOD PlotGraph.data(nCurves, nPoints)
public static void setDataFillValue(double dataFillValue)
Usage:                      PlotGraph.setDataFillValue(dataFillValue);
This static method changes the value of the variable, used by the method PlotGraph.data(nCurves, nPoints) to initialise the data array, from the default value of three time ten raised to the power 200 (3x10^200) to the value passed as the argument, e.g. dataFillValue in the above usage. See PlotGraph.data(nCurves, nPoints), immediately above, for details

GET THE ARRAY FILL VALUE USED BY THE METHOD PlotGraph.data(nCurves, nPoints)
public static double getDataFillValue()
Usage:                      double dataFillValue = PlotGraph.getDataFillValue();
This static method returns the value of the variable, used by the method PlotGraph.data(nCurves, nPoints) to initialise the data array. See PlotGraph.data(nCurves, nPoints), immediately above, for details.



PLOT AND DISPLAY THE GRAPH
public void plot()
Usage:                      pg.plot();
Scales, plots and displays, in its own window, the data entered onto the instance, pg. If the graph and axis legend information has not been entered (see optional but recommended in table above) the graph will not have full legend information. If this information has been entered the graph will be titled and the axis legends will contain the legend title, the units, any scaling factors and any offsets. The data is always scaled to give an axes maximum lying between 0.0 and 1.0.



OPTIONAL BUT STRONGLY RECOMMENDED METHODS

ENTER THE GRAPH TITLE
public void setGraphTitle(String gTitle)
Usage:                      pg.setGraphTitle(gTitle);
Enters the graph title contained in the String gTitle.

public void setGraphTitle2(String gTitle2)
Usage:                      pg.setGraphTitle2(gTitle2);
Enters a second line to the graph title. This optional method is useful if graph title is too long to fit on one line of the graph window.

ENTER THE ABSCISSA (HORIZONTAL) AXIS LEGEND
public void setXaxisLegend(String xLeg)
Usage:                      pg.setXaxisLegend(xLeg);
Enters the abscissa (horizontal) axis legend contained in the String xLeg.

ENTER THE ABSCISSA (HORIZONTAL) AXIS UNITS
public void setXaxisUnitsName(String xUnits)
Usage:                      pg.setXaxisUnitsName(xUnits);
Enters the abscissa (horizontal) axis units, e.g. V, contained in the String xUnits.

ENTER THE ORDINATE (VERTICAL) AXIS LEGEND
public void setYaxisLegend(String yLeg)
Usage:                      pg.setYaxisLegend(yLeg);
Enters the ordinate (vertical) axis legend contained in the String yLeg.

ENTER THE ORDINATE (VERTICAL) AXIS UNITS
public void setYaxisUnitsName(String yUnits)
Usage:                      pg.setYaxisUnitsName(yUnits);
Enters the ordinate (vertical) axis units, e.g. W, contained in the String yUnits.



OPTIONAL METHODS

ENTER ERROR BARS
public void setErrorBars(int nc, double[ ] err)
Usage:                      pg.setErrorBars(nc, err);
This method allows a set of errors to be plotted as error bars. The first argument, e.g. nc, is the number of the curve to which the error bars are to be added [REMEMBER! curve indices start at 0]. The second argument, e.g. err, is an array of doubles containing the errors for all points on that curve. They should be estimates of the standard deviation of each point. Error bars for two or more curves have to be entered separately, i.e. by individual calls to setErrorBars().

OVERWRITE THE PRESET LINE PLOTTING OPTIONS
public void setLine(int[] lineOpt)
public void setLine(int lineOpt)
Usage:                      pg.setLine(lopt);
If the argument, e.g. lopt, is an integer array of length equal to the number of curves, each element of the array should contain a value of 0, 1, 2 or 3, the lineOpt value for the curve corresponding to that array index, e.g. lopt[0] for the first curve, lopt[1] for the second etc. The options are:
The values in the argument array will overwrite the preset default options which are lineOpt=1 for all curves.
If the argument, e.g. lopt, is a single integer value, i.e. not an array, lineOpt will be assigned its value for all curves.

GET THE LINE PLOTTING OPTIONS
public int[] getLine()
Usage:                      int[ ] lopt = pg.getLine();
Returns an integer array of length equal to the number of curves. Each element of the array contains a value of 0, 1, 2 or 3, the lineOpt value for the curve corresponding to that array index, e.g. lopt[0] for the first curve, lopt[1] for the second etc. The options are: The preset default option is lineOpt=1 for all curves.

OVERWRITE THE NUMBER OF INTERPOLATION POINTS
public void setNiPoints(int niPoints)
Usage:                     pg.setNiPoints(niPoints);
Resets the number of interpolation points used in line plotting option , lineOpt = 1, (See Get and Overwrite line plotting options above). Overwrites the preset value of 200.

GET THE NUMBER OF INTERPOLATION POINTS
public int getNiPoints()
Usage:                      int nip = pg.getNiPoints();
Returns the number of interpolation points used in line plotting option , lineOpt = 1, (See Get and Overwrite line plotting options above). The preset default option is 200.

OVERWRITE THE LENGTH OF THE DASH IN A DASHED CURVE
public void setDashLength(int[] dlength)
public void setDashLength(int dlength)
Usage:                     pg.setDashLength(dlength);
If the argument, e.g. dlength, is an integer array of length equal to the number of curves, each element of the array should contain a value equal to the number of interpolation points per dash used in line plotting option, lineOpt = 2, (See Get and Overwrite line plotting options above) for the curve corresponding to that array index, e.g. dlength[0] for the first curve, dlength[1] for the second etc. Overwrites the preset value of 5.
If the argument, e.g. dlength, is a single integer value, i.e. not an array, dlength will be the value assigned to all all curves.

GET THE LENGTH OF THE DASH IN A DASHED CURVE
public int[] getDashLength()
Usage:                      int[ ] dashLength = pg.getDashLength();
Returns an integer array of length equal to the number of curves. Each element of the array contains a value of the dash length, used in plotting option, lineOpt=2, as described immediately above.

OVERWRITE THE PRESET POINT PLOTTING OPTIONS
public void setPoint(int[] pointOpt)
public void setPoint(int pointOpt)
Usage:                      pg.setPoint(popt);
If the argument, e.g. popt, is an integer array of length equal to the number of curves, each element of the array should contain a value from 0 to 8, the pointOpt value for the curve corresponding to that array index, e.g. popt[0] for the first curve, popt[1] for the second etc. The options are:
                    pointOpt = 0: no points are plotted;
                    pointOpt = 1: data points are plotted as open circles.
                    pointOpt = 2: data points are plotted as open squares.
                    pointOpt = 3: data points are plotted as open diamonds.
                    pointOpt = 4: data points are plotted as filled circles.
                    pointOpt = 5: data points are plotted as filled squares.
                    pointOpt = 6: data points are plotted as filled diamonds.
                    pointOpt = 7: data points are plotted as x crosses.
                    pointOpt = 8: data points are plotted as + crosses.
The values in the argument array will overwrite the preset default options which are pointOpt = 1 for the first curve; = 2 for the second curve; = 3 for the third curve; = 4 for the fourth curve; = 5 for the fifth curve; = 6 for the sixth curve; = 7 for the seventh curve; = 8 for the eigth curve and then repeats this sequence for further curves.
If the argument, e.g. popt, is a single integer value, i.e. not an array, pointOpt will be assigned its value for all curves.

GET THE POINT PLOTTING OPTIONS
public int[] getPoint()
Usage:                      int[ ] popt = pg.getPoint();
Returns an integer array of length equal to the number of curves. Each element of the array contains a value from 0 to 8, the pointOpt value for the curve corresponding to that array index, e.g. popt[0] for the first curve, popt[1] for the second etc. The options are:
                    pointOpt = 0: no points are plotted;
                    pointOpt = 1: data points are plotted as open circles.
                    pointOpt = 2: data points are plotted as open squares.
                    pointOpt = 3: data points are plotted as open diamonds.
                    pointOpt = 4: data points are plotted as filled circles.
                    pointOpt = 5: data points are plotted as filled squares.
                    pointOpt = 6: data points are plotted as filled diamonds.
                    pointOpt = 7: data points are plotted as x crosses.
                    pointOpt = 8: data points are plotted as + crosses.
The preset default option is pointOpt = 1 for the first curve; = 2 for the second curve; = 3 for the third curve; = 4 for the fourth curve; = 5 for the fifth curve; = 6 for the sixth curve; = 7 for the seventh curve; = 8 for the eigth curve and then repeats this sequence for further curves.

OVERWRITE THE PRESET POINT SIZES
public void setPointSize(int[] pointSize)
public void setPointSize(int pointSize)
Usage:                      pg.setPointSize(psize);
If the argument, e.g. psize, is an integer array of length equal to the number of curves, each element of the array should contain a the required point size, in pixels,7, for the curve corresponding to that array index, e.g. psize[0] for the first curve, psize[1] for the second etc. The values in argument array, e.g. psize, must be even integers. An odd integer will be rounded up to the next even integer.
If the argument, e.g. psize, is a single integer, i.e. not an array, all the points on all curves will be of that size.

GET THE POINT SIZES
public int[] getPointSize()
Usage:                      int[ ] psize = pg.getPointSize();
Returns an integer array of length equal to the number of curves. Each element of the array contains the size, in pixels, of the points for the curve corresponding to that array index, e.g. psize[0] for the first curve, psize[1] for the second etc. The preset default option is 6 for all curves.

RESET THE ABSCISSA (HORIZONTAL) AXIS LOWEST VALUE
public void setXlowFac(double xLowFac)
Usage:                     pg.setXlowFac(xLowFac);
The parameter, xLowFac, determines the value of the lowest point on the abscissa (horizontal) axis. If the lowest abscissa value is less than xLowFac times the highest abscissa value the lowest value on the scaled abscissa (horizontal) axis will be zero otherwise it will be set at the largest integer that is less than the lowest abscissa value. Overwrites the preset value of 0.25.
A value of 0.0 will ensure that the zero value is always included.

GET THE ABSCISSA (HORIZONTAL) AXIS LOW FACTOR
public double getXlowFac()
Usage:                      double xLowFac = pg.getXlowFac();
Returns the value of the abscissa (horizontal) axis low factor xLowFac. See
above for description of xLowFac.

RESET THE ORDINATE (VERTICAL) AXIS LOWEST VALUE
public void setYlowFac(double yLowFac)
Usage:                     pg.setYlowFac(yLowFac);
The parameter, yLowFac, determines the value of the lowest point on the ordinate (vertical) axis. If the lowest ordinate value is less than yLowFac times the highest ordinate value the lowest value on the scaled ordinate (vertical) axis will be zero otherwise it will be set at the largest integer that is less than the lowest ordinate value. Overwrites the preset value of 0.25.
A value of o.0 will ensure that the zero value is always included.

GET THE ORDINATE (VERTICAL) AXIS LOW FACTOR
public double getYlowFac()
Usage:                      double yLowFac = pg.getYlowFac();
Returns the value of the ordinate (vertical) axis low factor yLowFac. See
above for description of yLowFac.

RESET THE ABSCISSA (HORIZONTAL) AXIS OFFSET OPTION
public void setNoXoffset(boolean noXoffset)
Usage:                     pg.setNoXoffset(noXoffset);
Sets the abscissa (horizontal) axis offset option to e.g. the boolean noXoffset in the above usage. If the boolean argument is false, PlotGraph calculates an offset value for the abscissa axis if appropriate. If true, the data is always plotted without any offset. The default value is false. Offsetting comes into play when the range of values is much less than the lowest value, e.g the range 1000.1, 1000.3, 1000.6 would be offset by 1000.0

GET THE ABSCISSA (HORIZONTAL) AXIS OFFSET OPTION
public boolean getNoXoffset()
Usage:                     boolean xOffset = pg.getNoXoffset();
Returns the abscissa (horizontal) axis offset option. If the boolean argument is false, PlotGraph calculates an offset value for the abscissa if appropriate. If true, the data is always plotted without any offset. The default value is false.

GET THE ORDINATE (VERTICAL) AXIS OFFSET OPTION
public boolean getNoYoffset()
Usage:                     boolean yOffset = pg.getNoYoffset();
Returns the ordinate (vertical) axis offset option. If the boolean argument is false, PlotGraph calculates an offset value for the ordinate if appropriate. If true, the data is always plotted without any offset. The default value is false. Offsetting comes into play when the range of values is much less than the lowest value, e.g the range 1000.1, 1000.3, 1000.6 would be offset by 1000.0

RESET THE ORDINATE (VERTICAL) AXIS OFFSET OPTION
public void setNoYoffset(boolean noYoffset)
Usage:                     pg.setNoYoffset(noYoffset);
Sets the ordinate (vertical) axis offset option to e.g. the boolean noYoffset in the above usage. If the boolean argument is false, PlotGraph calculates an offset value for the ordinate axis if appropriate. If true, the data is always plotted without any offset. The default value is false.

RESET THE ABSCISSA AND ORDINATE AXES OFFSET OPTIONS
public void setNoOffset(boolean noOffset)
Usage:                     pg.setNoOffset(noOffset);
Sets the abscissa (horizontal) axis and ordinate (verical axis) offset options to the same value, e.g. to the boolean noOffset in the above usage. If the boolean argument is false, PlotGraph calculates an offset value for the abscissa and/or ordinate axes if appropriate. If true, the data is always plotted without any offset. The default value is false.

RESCALING
The graph window and plotted graph may be rescaled by: RESCALING THE ABSCISSA AXIS (HORIZONTAL DIMENSION)
public void rescaleXdim(double xScaleFac)
Usage:                      pg.rescaleXdim(xScaleFac);
Rescales the abscissa axis (x dimension), i.e. graph window width and abscissa (horizontal) axis length, by the argument, e.g. xScaleFac above.

RESCALING THE ORDINATE AXIS (VERTICAL DIMENSION)
public void rescaleYdim(double yScaleFac)
Usage:                      pg.rescaleYdim(yScaleFac);
Rescales the ordinate axis (vertical dimension), i.e. graph window height and ordinate (vertical) axis length, by the argument, e.g. yScaleFac above.

RESET THE WINDOW CLOSING OPTION
public void setCloseChoice(int closeChoice)
Usage:                     pg.setCloseChoice(closecho ice);
Resets the window closing option, closeChoice.
If closeChoice = 1 clicking on the graph window close icon (x cross box in the top right hand corner) closes the window and the program is exited.
If closeChoice = 2 clicking on the graph window close icon closes the window but leaves the program running.
Overwrites the preset value of 1.

GET THE WINDOW CLOSING OPTION
public int getCloseChoice()
Usage:                      int closeChoice = pg.getCloseChoice();
Returns the value of the closeChoice parameter. See
above for description of closeChoice.

RESET THE HEIGHT OF THE GRAPH WINDOW
public void setGraphHeight(int graphHeight)
Usage:                     pg.setGraphHeight(graphhei ght);
Resets the height, in pixels, of the graph window. Overwrites the preset value of 600. See also
Rescaling.

GET THE HEIGHT OF THE GRAPH WINDOW
public int getGraphHeight()
Usage:                      int graphHeight = pg.getGraphHeight();
Returns the value of the height, in pixels, of the graph window.

RESET THE WIDTH OF THE GRAPH WINDOW
public void setGraphWidth(int graphWidth)
Usage:                     pg.setGraphWidth(graphWidth);
Resets the width, in pixels, of the graph window. Overwrites the preset value of 800. See also
Rescaling.

GET THE WIDTH OF THE GRAPH WINDOW
public int getGraphWidth()
Usage:                      int graphWidth = pg.getGraphWidth();
Returns the value of the width, in pixels, of the graph window.

RESET THE LENGTH OF THE ABSCISSA (HORIZONTAL) AXIS
public void setXaxisLen(int xLen)
Usage:                     pg.setXaxisLen(xLen);
Resets the length, in pixels, of the abscissa (horizontal) axis. Overwrites the preset value of 625. See also
Rescaling.

GET THE LENGTH OF THE ABSCISSA (HORIZONTAL) AXIS
public int getXaxisLen()
Usage:                      int xLen = pg.getXaxisLen();
Returns the value of the length, in pixels, of the abscissa (horizontal) axis.

RESET THE LENGTH OF THE ORDINATE (VERTICAL) AXIS
public void setYaxisLen(int yLen)
Usage:                     pg.setYaxisLen(yLen);
Resets the length, in pixels, of the ordinate (vertical) axis. Overwrites the preset value of 375. See also
Rescaling.

GET THE LENGTH OF THE ORDINATE (VERTICAL) AXIS
public int getYaxisLen()
Usage:                      int yLen = pg.getYaxisLen();
Returns the value of the length, in pixels, of the ordinate (vertical) axis.

RESET THE START OF THE ABSCISSA (HORIZONTAL) AXIS
public void setXlow(int xbot)
Usage:                     pg.setXlow(xbot);
Resets the x position, in pixels, of the start of the abscissa (horizontal) axis. Remember the window co-ordinate frame's zero (0, 0) is the top left hand corner of the window. Overwrites the preset value of 100. See also
Rescaling.

GET THE START OF THE ABSCISSA (HORIZONTAL) AXIS
public int getXlow()
Usage:                      int xbot = pg.getXlow();
Returns the x position, in pixels, of the start of the abscissa (horizontal) axis. Remember the window co-ordinate frame's zero (0, 0) is the top left hand corner of the window.

RESET THE TOP OF THE ORDINATE (VERTICAL) AXIS
public void setYhigh(int yTop)
Usage:                     pg.setYhigh(yTop);
Resets the y position, in pixels, of the top of the ordinate (vertical) axis. Remember the window co-ordinate frame's zero (0, 0) is the top left hand corner of the window. Overwrites the preset value of 110. See also
Rescaling.

GET THE TOP OF THE ORDINATE (VERTICAL) AXIS
public int getYhigh()
Usage:                      int yTop = pg.getYhigh();
Returns the y position, in pixels, of the top of the ordinate (vertical) axis. Remember the window co-ordinate frame's zero (0, 0) is the top left hand corner of the window.

GET THE MINIMUM VALUE OF THE ABSCISSA (HORIZONTAL) AXIS
public double getXmin()
Usage:                      double xmin = pg.getXmin();
Returns the minimum value of the abscissa (horizontal) axis.

GET THE MAXIMUM VALUE OF THE ABSCISSA (HORIZONTAL) AXIS
public double getXmax()
Usage:                      double xmax = pg.getXmax();
Returns the maximum value of the abscissa (horizontal)axis.

GET THE MINIMUM VALUE OF THE ORDINATE (VERTICAL) AXIS
public double getYmin()
Usage:                      double ymin = pg.getYmin();
Returns the minimum value of the ordinate (vertical) axis.

GET THE MAXIMUM VALUE OF THE ORDINATE (VERTICAL) AXIS
public double getYmax()
Usage:                      double ymax = pg.getYmax();
Returns the maximum value of the ordinate (vertical) axis.

ENDING AN APPLICATION THAT USES PlotGraph
public void endProgram()
Usage:
                     pg.endProgram();

This method displays a dialogue box that asks if you want to end the program. Answering yes ends the program. Answering no displays a message telling you how you may now end the program. Ending the program also closes the graph window or windows.

Any application that you write that displays a graphical user interface, as the plotting method in this class, PlotGraph, does, must be terminated:
  1. with the line System.exit(0);
  2. or by calling a method that contains that statement, e.g. by calling endProgram()
  3. or, in the special case of PlotGraph, by closing the graph window if window closing option (see setCloseChoice above) is set at 1, i.e. at the default option.
Options 2 or 3 are recommended in the case of applications using PlotGraph.



EXAMPLE PROGRAM

The example program Plotter.java illustrates the plotting of two curves on the same graph.
A data file for use with this example can be found on TestPlotter.txt



OTHER CLASSES USED BY THIS CLASS

This class uses the following classes in this library:



This page was prepared by Dr Michael Thomas Flanagan