Class Plot
- java.lang.Object
-
- edu.rit.numeric.plot.Plot
-
- All Implemented Interfaces:
- Displayable, Drawable, Viewable, java.io.Externalizable, java.io.Serializable
public class Plot extends java.lang.Object implements Viewable, java.io.Externalizable
Class Plot is a class for creating and displaying a plot.To create a plot, construct an instance of class Plot, and call the desired methods to specify attributes of the plot and to provide the data to be plotted.
To display a plot, call the getFrame() method to get a DisplayableFrame that displays the plot in a window, then call the frame's setVisible(true) method. The frame has menus for zooming the display, for changing the plot's attributes (title, margins, grid, X axis, Y axis, etc.), and for saving the plot in a PNG or PostScript file.
If the plot's attributes are changed after displaying the frame, call the frame's display() method, passing in a reference to the plot object. If the data in the plot's X-Y series are changed after displaying the frame, but the plot's attributes are not changed, call the frame's repaint() method.
A Plot object can be written (serialized) into a file. The View program can be used to display the file.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classPlot.AxisKindEnum Plot.AxisKind enumerates the possible kinds of axis on a Plot.
-
Field Summary
Fields Modifier and Type Field and Description static intABOVEThe label is positioned above its location.static intABOVE_LEFTThe label is positioned above and to the left of its location.static intABOVE_RIGHTThe label is positioned above and to the right of its location.static intBELOWThe label is positioned below its location.static intBELOW_LEFTThe label is positioned below and to the left of its location.static intBELOW_RIGHTThe label is positioned below and to the right of its location.static intCENTERThe label is centered on its location.static intLEFTThe label is positioned to the left of its location.static Plot.AxisKindLINEARLinear axis.static Plot.AxisKindLOGARITHMICLogarithmic axis.static intPIXEL_COORDINATESThe label's location is specified in pixel coordinates relative to the lower left corner of the plot area, rather than in plot coordinates.static intRIGHTThe label is positioned to the right of its location.static intROTATE_AROUNDThe label is rotated 180 degrees around.static intROTATE_LEFTThe label is rotated 90 degrees left (counterclockwise).static intROTATE_RIGHTThe label is rotated 90 degrees right (clockwise).
-
Constructor Summary
Constructors Constructor and Description Plot()Construct a new plot.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description PlotbottomMargin(double theMargin)Set the bottom margin for the plot.voiddraw(java.awt.Graphics2D g2d)Draw this drawable object in the given graphics context.PlotframeTitle(java.lang.String theTitle)Set the title for the frame that displays the plot.java.awt.PaintgetBackgroundPaint()Returns this displayable object's background paint.java.awt.geom.Rectangle2DgetBoundingBox()Returns this displayable object's bounding box.DisplayableFramegetFrame()Get a displayable frame in which to view this viewable object.java.lang.StringgetTitle()Get the title for the frame used to view this viewable object.Plotlabel(java.lang.String text, double x, double y)Add a label to this plot.PlotlabelBackground(java.awt.Color theColor)Set the color to use for label backgrounds.PlotlabelColor(java.awt.Color theColor)Set the color to use for labels.PlotlabelFont(java.awt.Font theFont)Set the font to use for labels.PlotlabelOffset(double theOffset)Set the offset to use for labels.PlotlabelPosition(int thePosition)Set the positioning to use for labels.PlotleftMargin(double theMargin)Set the left margin for the plot.PlotmajorGridLines(boolean theGridLines)Specify whether major division grid lines are drawn on the plot.Plotmargins(double theMargin)Set the margins for the plot.PlotminorGridLines(boolean theGridLines)Specify whether minor division grid lines are drawn on the plot.PlotplotTitle(java.lang.String theTitle)Set the title for the plot.PlotplotTitleFont(java.awt.Font theTitleFont)Set the title font for the plot.PlotplotTitleOffset(double theTitleOffset)Set the offset from the plot area to the title for the plot.static Plotread(java.io.File theFile)Read a plot from the given file.static Plotread(java.lang.String theFileName)Read a plot from the file with the given name.voidreadExternal(java.io.ObjectInput in)Read this plot from the given object input stream.PlotrightMargin(double theMargin)Set the right margin for the plot.PlotsegmentedSeries(double... theData)Add a segmented data series to this plot with data points taken from the arguments.PlotsegmentedSeries(double[] theXArray, double[] theYArray)Add a segmented data series to this plot with data points taken from the two arrays.PlotsegmentedSeries(java.io.File theFile)Add a segmented data series to this plot with data points read from the given file.PlotsegmentedSeries(java.io.InputStream theInputStream)Add a segmented data series to this plot with data points read from the given input stream.PlotsegmentedSeries(java.util.Scanner theScanner)Add a segmented data series to this plot with data points read from the given scanner.PlotsegmentedSeries(java.lang.String theFileName)Add a segmented data series to this plot with data points read from the file with the given name.PlotsegmentedSeries(XYSeries theXYSeries)Add a segmented data series to this plot with data points taken from the given XYSeries.PlotseriesColor(java.awt.Color theColor)Set the color to use for line segments when plotting a data series.PlotseriesDots(Dots theDots)Set the dots to use when plotting a data series.PlotseriesSmooth(boolean isSmooth)Specify whether to draw a smooth curve when plotting a data series.PlotseriesStroke(java.awt.BasicStroke theStroke)Set the stroke to use for line segments when plotting a data series.PlottopMargin(double theMargin)Set the top margin for the plot.static voidwrite(Plot thePlot, java.io.File theFile)Write the given plot to the given file.static voidwrite(Plot thePlot, java.lang.String theFileName)Write the given plot to the file with the given name.voidwriteExternal(java.io.ObjectOutput out)Write this plot to the given object output stream.PlotxAxisCrossing(double theCrossing)Set the perpendicular axis crossing value for the X axis.PlotxAxisEnd(double theEnd)Set the ending value for the X axis.PlotxAxisKind(Plot.AxisKind theKind)Set the kind of axis for the X axis.PlotxAxisLength(double theLength)Set the length of the X axis.PlotxAxisMajorDivisions(int theMajorDivisions)Set the number of major divisions for the X axis.PlotxAxisMinorDivisions(int theMinorDivisions)Set the number of minor divisions per major division for the X axis.PlotxAxisStart(double theStart)Set the starting value for the X axis.PlotxAxisTickFont(java.awt.Font theTickFont)Set the tick label font for the X axis.PlotxAxisTickFormat(java.text.DecimalFormat theTickFormat)Set the tick label format for the X axis.PlotxAxisTickScale(double theTickScale)Set the tick label scale factor for the X axis.PlotxAxisTitle(java.lang.String theTitle)Set the title for the X axis.PlotxAxisTitleFont(java.awt.Font theTitleFont)Set the title font for the X axis.PlotxAxisTitleOffset(double theTitleOffset)Set the offset from the axis to the title for the X axis.PlotxySeries(double... theData)Add an X-Y data series to this plot with data points taken from the arguments.PlotxySeries(double[] theXArray, double[] theYArray)Add an X-Y data series to this plot with data points taken from the two arrays.PlotxySeries(java.io.File theFile)Add an X-Y data series to this plot with data points read from the given file.PlotxySeries(java.io.InputStream theInputStream)Add an X-Y data series to this plot with data points read from the given input stream.PlotxySeries(java.util.Scanner theScanner)Add an X-Y data series to this plot with data points read from the given scanner.PlotxySeries(java.lang.String theFileName)Add an X-Y data series to this plot with data points read from the file with the given name.PlotxySeries(XYSeries theXYSeries)Add an X-Y data series to this plot with data points taken from the given XYSeries.PlotyAxisCrossing(double theCrossing)Set the perpendicular axis crossing value for the Y axis.PlotyAxisEnd(double theEnd)Set the ending value for the Y axis.PlotyAxisKind(Plot.AxisKind theKind)Set the kind of axis for the Y axis.PlotyAxisLength(double theLength)Set the length of the Y axis.PlotyAxisMajorDivisions(int theMajorDivisions)Set the number of major divisions for the Y axis.PlotyAxisMinorDivisions(int theMinorDivisions)Set the number of minor divisions per major division for the X axis.PlotyAxisStart(double theStart)Set the starting value for the Y axis.PlotyAxisTickFont(java.awt.Font theTickFont)Set the tick label font for the Y axis.PlotyAxisTickFormat(java.text.DecimalFormat theTickFormat)Set the tick label format for the Y axis.PlotyAxisTickScale(double theTickScale)Set the tick label scale factor for the Y axis.PlotyAxisTitle(java.lang.String theTitle)Set the title for the Y axis.PlotyAxisTitleFont(java.awt.Font theTitleFont)Set the title font for the Y axis.PlotyAxisTitleOffset(double theTitleOffset)Set the offset from the axis to the title for the Y axis.
-
-
-
Field Detail
-
LINEAR
public static final Plot.AxisKind LINEAR
Linear axis.
-
LOGARITHMIC
public static final Plot.AxisKind LOGARITHMIC
Logarithmic axis.
-
ABOVE_LEFT
public static final int ABOVE_LEFT
The label is positioned above and to the left of its location.- See Also:
- Constant Field Values
-
ABOVE
public static final int ABOVE
The label is positioned above its location.- See Also:
- Constant Field Values
-
ABOVE_RIGHT
public static final int ABOVE_RIGHT
The label is positioned above and to the right of its location.- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
The label is positioned to the left of its location.- See Also:
- Constant Field Values
-
CENTER
public static final int CENTER
The label is centered on its location.- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
The label is positioned to the right of its location.- See Also:
- Constant Field Values
-
BELOW_LEFT
public static final int BELOW_LEFT
The label is positioned below and to the left of its location.- See Also:
- Constant Field Values
-
BELOW
public static final int BELOW
The label is positioned below its location.- See Also:
- Constant Field Values
-
BELOW_RIGHT
public static final int BELOW_RIGHT
The label is positioned below and to the right of its location.- See Also:
- Constant Field Values
-
ROTATE_LEFT
public static final int ROTATE_LEFT
The label is rotated 90 degrees left (counterclockwise).- See Also:
- Constant Field Values
-
ROTATE_RIGHT
public static final int ROTATE_RIGHT
The label is rotated 90 degrees right (clockwise).- See Also:
- Constant Field Values
-
ROTATE_AROUND
public static final int ROTATE_AROUND
The label is rotated 180 degrees around.- See Also:
- Constant Field Values
-
PIXEL_COORDINATES
public static final int PIXEL_COORDINATES
The label's location is specified in pixel coordinates relative to the lower left corner of the plot area, rather than in plot coordinates.- See Also:
- Constant Field Values
-
-
Method Detail
-
frameTitle
public Plot frameTitle(java.lang.String theTitle)
Set the title for the frame that displays the plot. The default is the same as the plot title.- Parameters:
theTitle- Title.- Returns:
- This plot object.
-
plotTitle
public Plot plotTitle(java.lang.String theTitle)
Set the title for the plot. The default is no title.- Parameters:
theTitle- Title.- Returns:
- This plot object.
-
plotTitleFont
public Plot plotTitleFont(java.awt.Font theTitleFont)
Set the title font for the plot. The default is sans-serif, plain, 14 point.- Parameters:
theTitleFont- Title font.- Returns:
- This plot object.
-
plotTitleOffset
public Plot plotTitleOffset(double theTitleOffset)
Set the offset from the plot area to the title for the plot. The default is 9 points.- Parameters:
theTitleOffset- Title offset (points).- Returns:
- This plot object.
-
margins
public Plot margins(double theMargin)
Set the margins for the plot. This is the distance from the left, top, right, and bottom sides of the plot area to the left, top, right, and bottom sides of the display.- Parameters:
theMargin- Margin (points).- Returns:
- This plot object.
-
leftMargin
public Plot leftMargin(double theMargin)
Set the left margin for the plot. This is the distance from the left side of the plot area to the left side of the display. The default is 54 points.- Parameters:
theMargin- Left margin (points).- Returns:
- This plot object.
-
topMargin
public Plot topMargin(double theMargin)
Set the top margin for the plot. This is the distance from the top side of the plot area to the top side of the display. The default is 27 points.- Parameters:
theMargin- Top margin (points).- Returns:
- This plot object.
-
rightMargin
public Plot rightMargin(double theMargin)
Set the right margin for the plot. This is the distance from the right side of the plot area to the right side of the display. The default is 27 points.- Parameters:
theMargin- Right margin (points).- Returns:
- This plot object.
-
bottomMargin
public Plot bottomMargin(double theMargin)
Set the bottom margin for the plot. This is the distance from the bottom side of the plot area to the bottom side of the display. The default is 54 points.- Parameters:
theMargin- Bottom margin (points).- Returns:
- This plot object.
-
majorGridLines
public Plot majorGridLines(boolean theGridLines)
Specify whether major division grid lines are drawn on the plot. The default is to draw major division grid lines.- Parameters:
theGridLines- True to draw major division grid lines, false not to draw them.- Returns:
- This plot object.
-
minorGridLines
public Plot minorGridLines(boolean theGridLines)
Specify whether minor division grid lines are drawn on the plot. The default is not to draw minor division grid lines.- Parameters:
theGridLines- True to draw minor division grid lines, false not to draw them.- Returns:
- This plot object.
-
xAxisKind
public Plot xAxisKind(Plot.AxisKind theKind)
Set the kind of axis for the X axis. The default is a linear axis.- Parameters:
theKind-LINEARorLOGARITHMIC.- Returns:
- This plot object.
-
xAxisStart
public Plot xAxisStart(double theStart)
Set the starting value for the X axis. For a linear axis, this is the actual starting value. For a logarithmic axis, this the base-10 logarithm of the starting value, and it is truncated to the nearest integer. The default is to determine the starting value automatically from the plotted data.- Parameters:
theStart- Starting value.- Returns:
- This plot object.
-
xAxisEnd
public Plot xAxisEnd(double theEnd)
Set the ending value for the X axis. For a linear axis, this is the actual ending value. For a logarithmic axis, this the base-10 logarithm of the ending value, and it is truncated to the nearest integer. The default is to determine the ending value automatically from the plotted data.- Parameters:
theEnd- Ending value.- Returns:
- This plot object.
-
xAxisMajorDivisions
public Plot xAxisMajorDivisions(int theMajorDivisions)
Set the number of major divisions for the X axis. The default is 10 major divisions.For a logarithmic axis, theMajorDivisions is ignored; each factor of 10 between the starting and ending values is one major division.
- Parameters:
theMajorDivisions- Number of major divisions.- Returns:
- This plot object.
-
xAxisMinorDivisions
public Plot xAxisMinorDivisions(int theMinorDivisions)
Set the number of minor divisions per major division for the X axis. The default is 1 minor division per major division.- Parameters:
theMinorDivisions- Number of minor divisions per major division.- Returns:
- This plot object.
-
xAxisCrossing
public Plot xAxisCrossing(double theCrossing)
Set the perpendicular axis crossing value for the X axis. For a linear axis, this is the actual crossing value. For a logarithmic axis, this the base-10 logarithm of the crossing value, and it is truncated to the nearest integer. The default is for the perpendicular axis to cross at the X axis's starting value.- Parameters:
theCrossing- Perpendicular axis crossing value.- Returns:
- This plot object.
-
xAxisLength
public Plot xAxisLength(double theLength)
Set the length of the X axis. The default is 288 points.- Parameters:
theLength- Axis length (points).- Returns:
- This plot object.
-
xAxisTickFormat
public Plot xAxisTickFormat(java.text.DecimalFormat theTickFormat)
Set the tick label format for the X axis. If theTickFormat is null, tick labels will not be drawn on the X axis. The default is a decimal format of "0".- Parameters:
theTickFormat- Tick format, or null.- Returns:
- This plot object.
-
xAxisTickScale
public Plot xAxisTickScale(double theTickScale)
Set the tick label scale factor for the X axis. Each tick mark's numerical value is divided by the scale factor before being displayed. The default is 1 (no scaling).- Parameters:
theTickScale- Tick scale factor.- Returns:
- This plot object.
-
xAxisTickFont
public Plot xAxisTickFont(java.awt.Font theTickFont)
Set the tick label font for the X axis. The default is sans-serif, plain, 12 point.- Parameters:
theTickFont- Tick font.- Returns:
- This plot object.
-
xAxisTitle
public Plot xAxisTitle(java.lang.String theTitle)
Set the title for the X axis. The default is no title.- Parameters:
theTitle- Title.- Returns:
- This plot object.
-
xAxisTitleFont
public Plot xAxisTitleFont(java.awt.Font theTitleFont)
Set the title font for the X axis. The default is sans-serif, plain, 12 point.- Parameters:
theTitleFont- Title font.- Returns:
- This plot object.
-
xAxisTitleOffset
public Plot xAxisTitleOffset(double theTitleOffset)
Set the offset from the axis to the title for the X axis. The default is 30 points.- Parameters:
theTitleOffset- Title offset (points).- Returns:
- This plot object.
-
yAxisKind
public Plot yAxisKind(Plot.AxisKind theKind)
Set the kind of axis for the Y axis. The default is a linear axis.- Parameters:
theKind-LINEARorLOGARITHMIC.- Returns:
- This plot object.
-
yAxisStart
public Plot yAxisStart(double theStart)
Set the starting value for the Y axis. For a linear axis, this is the actual starting value. For a logarithmic axis, this the base-10 logarithm of the starting value, and it is truncated to the nearest integer. The default is to determine the starting value automatically from the plotted data.- Parameters:
theStart- Starting value.- Returns:
- This plot object.
-
yAxisEnd
public Plot yAxisEnd(double theEnd)
Set the ending value for the Y axis. For a linear axis, this is the actual ending value. For a logarithmic axis, this the base-10 logarithm of the ending value, and it is truncated to the nearest integer. The default is to determine the ending value automatically from the plotted data.- Parameters:
theEnd- Ending value.- Returns:
- This plot object.
-
yAxisMajorDivisions
public Plot yAxisMajorDivisions(int theMajorDivisions)
Set the number of major divisions for the Y axis. The default is 10 major divisions.For a logarithmic axis, theMajorDivisions is ignored; each factor of 10 between the starting and ending values is one major division.
- Parameters:
theMajorDivisions- Number of major divisions.- Returns:
- This plot object.
-
yAxisMinorDivisions
public Plot yAxisMinorDivisions(int theMinorDivisions)
Set the number of minor divisions per major division for the X axis. The default is 1 minor division per major division.- Parameters:
theMinorDivisions- Number of minor divisions per major division.- Returns:
- This plot object.
-
yAxisCrossing
public Plot yAxisCrossing(double theCrossing)
Set the perpendicular axis crossing value for the Y axis. For a linear axis, this is the actual crossing value. For a logarithmic axis, this the base-10 logarithm of the crossing value, and it is truncated to the nearest integer. The default is for the perpendicular axis to cross at the Y axis's starting value.- Parameters:
theCrossing- Perpendicular axis crossing value.- Returns:
- This plot object.
-
yAxisLength
public Plot yAxisLength(double theLength)
Set the length of the Y axis. The default is 288 points.- Parameters:
theLength- Axis length (points).- Returns:
- This plot object.
-
yAxisTickFormat
public Plot yAxisTickFormat(java.text.DecimalFormat theTickFormat)
Set the tick label format for the Y axis. If theTickFormat is null, tick labels will not be drawn on the Y axis. The default is a decimal format of "0".- Parameters:
theTickFormat- Tick format, or null.- Returns:
- This plot object.
-
yAxisTickScale
public Plot yAxisTickScale(double theTickScale)
Set the tick label scale factor for the Y axis. Each tick mark's numerical value is divided by the scale factor before being displayed. The default is 1 (no scaling).- Parameters:
theTickScale- Tick scale factor.- Returns:
- This plot object.
-
yAxisTickFont
public Plot yAxisTickFont(java.awt.Font theTickFont)
Set the tick label font for the Y axis. The default is sans-serif, plain, 12 point.- Parameters:
theTickFont- Tick font.- Returns:
- This plot object.
-
yAxisTitle
public Plot yAxisTitle(java.lang.String theTitle)
Set the title for the Y axis. The default is no title.- Parameters:
theTitle- Title.- Returns:
- This plot object.
-
yAxisTitleFont
public Plot yAxisTitleFont(java.awt.Font theTitleFont)
Set the title font for the Y axis. The default is sans-serif, plain, 12 point.- Parameters:
theTitleFont- Title font.- Returns:
- This plot object.
-
yAxisTitleOffset
public Plot yAxisTitleOffset(double theTitleOffset)
Set the offset from the axis to the title for the Y axis. The default is 36 points.- Parameters:
theTitleOffset- Title offset (points).- Returns:
- This plot object.
-
seriesDots
public Plot seriesDots(Dots theDots)
Set the dots to use when plotting a data series. All data series added hereafter will use the given dots. The default is a solid black circle 5 points in diameter. See class Dots for other shapes.- Parameters:
theDots- Dots, or null not to plot dots.- Returns:
- This plot object.
-
seriesStroke
public Plot seriesStroke(java.awt.BasicStroke theStroke)
Set the stroke to use for line segments when plotting a data series. All data series added hereafter will use the given stroke. The default is a solid stroke 2 points wide. See class Strokes for other strokes.- Parameters:
theStroke- Stroke, or null not to plot line segments.- Returns:
- This plot object.
-
seriesColor
public Plot seriesColor(java.awt.Color theColor)
Set the color to use for line segments when plotting a data series. All data series added hereafter will use the given color. The default is black.- Parameters:
theColor- Color, or null not to plot line segments.- Returns:
- This plot object.
-
seriesSmooth
public Plot seriesSmooth(boolean isSmooth)
Specify whether to draw a smooth curve when plotting a data series. All data series added hereafter will use the given smoothing. The default is false (draw straight line segments).- Parameters:
isSmooth- True to draw a smooth curve, false to draw straight line segments.- Returns:
- This plot object.
-
xySeries
public Plot xySeries(java.lang.String theFileName) throws java.io.FileNotFoundException
Add an X-Y data series to this plot with data points read from the file with the given name. Double values are read from the file until there are no more. Each pair of double values becomes an (x,y) point in the data series. Any leftover double value is discarded.A dot is drawn at each data point as specified by the seriesDot() method. A line segment is drawn from each data point to the next as specified by the seriesStroke() and seriesColor() methods. A smooth curve is drawn, or not, as specified by the seriesSmooth() method.
- Parameters:
theFileName- File name.- Returns:
- This plot object.
- Throws:
java.io.FileNotFoundException- Thrown if the file could not be read.
-
xySeries
public Plot xySeries(java.io.File theFile) throws java.io.FileNotFoundException
Add an X-Y data series to this plot with data points read from the given file. Double values are read from the file until there are no more. Each pair of double values becomes an (x,y) point in the data series. Any leftover double value is discarded.A dot is drawn at each data point as specified by the seriesDot() method. A line segment is drawn from each data point to the next as specified by the seriesStroke() and seriesColor() methods. A smooth curve is drawn, or not, as specified by the seriesSmooth() method.
- Parameters:
theFile- File.- Returns:
- This plot object.
- Throws:
java.io.FileNotFoundException- Thrown if the file could not be read.
-
xySeries
public Plot xySeries(java.io.InputStream theInputStream)
Add an X-Y data series to this plot with data points read from the given input stream. Double values are read from the input stream until there are no more. Each pair of double values becomes an (x,y) point in the data series. Any leftover double value is discarded. After adding the data series, the input stream is closed.A dot is drawn at each data point as specified by the seriesDot() method. A line segment is drawn from each data point to the next as specified by the seriesStroke() and seriesColor() methods. A smooth curve is drawn, or not, as specified by the seriesSmooth() method.
- Parameters:
theInputStream- Input stream.- Returns:
- This plot object.
-
xySeries
public Plot xySeries(java.util.Scanner theScanner)
Add an X-Y data series to this plot with data points read from the given scanner. Double values are read from the scanner until there are no more. Each pair of double values becomes an (x,y) point in the data series. Any leftover double value is discarded. After constructing the data series, the scanner is closed.A dot is drawn at each data point as specified by the seriesDot() method. A line segment is drawn from each data point to the next as specified by the seriesStroke() and seriesColor() methods. A smooth curve is drawn, or not, as specified by the seriesSmooth() method.
- Parameters:
theScanner- Scanner.- Returns:
- This plot object.
-
xySeries
public Plot xySeries(double... theData)
Add an X-Y data series to this plot with data points taken from the arguments. The argument values are grouped into pairs, where the first argument value is the X value and the second argument value is the Y value. Each pair of argument values becomes one data point in the X-Y data series. It is assumed that there are an even number of argument values.A dot is drawn at each data point as specified by the seriesDot() method. A line segment is drawn from each data point to the next as specified by the seriesStroke() and seriesColor() methods. A smooth curve is drawn, or not, as specified by the seriesSmooth() method.
- Parameters:
theData- Data point X and Y coordinates.- Returns:
- This plot object.
-
xySeries
public Plot xySeries(double[] theXArray, double[] theYArray)
Add an X-Y data series to this plot with data points taken from the two arrays. The first array contains the X coordinates, the second array contains the Y coordinates.A dot is drawn at each data point as specified by the seriesDot() method. A line segment is drawn from each data point to the next as specified by the seriesStroke() and seriesColor() methods. A smooth curve is drawn, or not, as specified by the seriesSmooth() method.
- Parameters:
theXArray- Array of data point X coordinates.theYArray- Array of data point Y coordinates.- Returns:
- This plot object.
-
xySeries
public Plot xySeries(XYSeries theXYSeries)
Add an X-Y data series to this plot with data points taken from the given XYSeries.A dot is drawn at each data point as specified by the seriesDot() method. A line segment is drawn from each data point to the next as specified by the seriesStroke() and seriesColor() methods. A smooth curve is drawn, or not, as specified by the seriesSmooth() method.
- Parameters:
theXYSeries- X-Y series.- Returns:
- This plot object.
-
segmentedSeries
public Plot segmentedSeries(java.lang.String theFileName) throws java.io.FileNotFoundException
Add a segmented data series to this plot with data points read from the file with the given name. Double values are read from the file until there are no more. Each pair of double values becomes an (x,y) point in the data series. Any leftover double value is discarded.The data points are divided into pairs. Each pair of data points specifies the starting and ending coordinates of a line segment. A dot is drawn at each endpoint of each line segment. A line segment's starting coordinates need not be the same as the previous line segment's ending coordinates. If the data series has an odd number of data points, the last data point is ignored.
- Parameters:
theFileName- File name.- Returns:
- This plot object.
- Throws:
java.io.FileNotFoundException- Thrown if the file could not be read.
-
segmentedSeries
public Plot segmentedSeries(java.io.File theFile) throws java.io.FileNotFoundException
Add a segmented data series to this plot with data points read from the given file. Double values are read from the file until there are no more. Each pair of double values becomes an (x,y) point in the data series. Any leftover double value is discarded.The data points are divided into pairs. Each pair of data points specifies the starting and ending coordinates of a line segment. A dot is drawn at each endpoint of each line segment. A line segment's starting coordinates need not be the same as the previous line segment's ending coordinates. If the data series has an odd number of data points, the last data point is ignored.
- Parameters:
theFile- File.- Returns:
- This plot object.
- Throws:
java.io.FileNotFoundException- Thrown if the file could not be read.
-
segmentedSeries
public Plot segmentedSeries(java.io.InputStream theInputStream)
Add a segmented data series to this plot with data points read from the given input stream. Double values are read from the input stream until there are no more. Each pair of double values becomes an (x,y) point in the data series. Any leftover double value is discarded. After adding the data series, the input stream is closed.The data points are divided into pairs. Each pair of data points specifies the starting and ending coordinates of a line segment. A dot is drawn at each endpoint of each line segment. A line segment's starting coordinates need not be the same as the previous line segment's ending coordinates. If the data series has an odd number of data points, the last data point is ignored.
- Parameters:
theInputStream- Input stream.- Returns:
- This plot object.
-
segmentedSeries
public Plot segmentedSeries(java.util.Scanner theScanner)
Add a segmented data series to this plot with data points read from the given scanner. Double values are read from the scanner until there are no more. Each pair of double values becomes an (x,y) point in the data series. Any leftover double value is discarded. After constructing the data series, the scanner is closed.The data points are divided into pairs. Each pair of data points specifies the starting and ending coordinates of a line segment. A dot is drawn at each endpoint of each line segment. A line segment's starting coordinates need not be the same as the previous line segment's ending coordinates. If the data series has an odd number of data points, the last data point is ignored.
- Parameters:
theScanner- Scanner.- Returns:
- This plot object.
-
segmentedSeries
public Plot segmentedSeries(double... theData)
Add a segmented data series to this plot with data points taken from the arguments. The argument values are grouped into pairs, where the first argument value is the X value and the second argument value is the Y value. Each pair of argument values becomes one data point in the segmented data series. It is assumed that there are an even number of argument values.The data points are divided into pairs. Each pair of data points specifies the starting and ending coordinates of a line segment. A dot is drawn at each endpoint of each line segment. A line segment's starting coordinates need not be the same as the previous line segment's ending coordinates. If the data series has an odd number of data points, the last data point is ignored.
- Parameters:
theData- Data point X and Y coordinates.- Returns:
- This plot object.
-
segmentedSeries
public Plot segmentedSeries(double[] theXArray, double[] theYArray)
Add a segmented data series to this plot with data points taken from the two arrays. The first array contains the X coordinates, the second array contains the Y coordinates.The data points are divided into pairs. Each pair of data points specifies the starting and ending coordinates of a line segment. A dot is drawn at each endpoint of each line segment. A line segment's starting coordinates need not be the same as the previous line segment's ending coordinates. If the data series has an odd number of data points, the last data point is ignored.
- Parameters:
theXArray- Array of data point X coordinates.theYArray- Array of data point Y coordinates.- Returns:
- This plot object.
-
segmentedSeries
public Plot segmentedSeries(XYSeries theXYSeries)
Add a segmented data series to this plot with data points taken from the given XYSeries.The data points are divided into pairs. Each pair of data points specifies the starting and ending coordinates of a line segment. A dot is drawn at each endpoint of each line segment. A line segment's starting coordinates need not be the same as the previous line segment's ending coordinates. If the data series has an odd number of data points, the last data point is ignored.
- Parameters:
theXYSeries- X-Y series.- Returns:
- This plot object.
-
labelPosition
public Plot labelPosition(int thePosition)
Set the positioning to use for labels. All labels added hereafter will use the given positioning. The label positioning argument must be one of the following constants to specify how the label is positioned relative to the label's (x,y) location:ABOVE_LEFT,ABOVE,ABOVE_RIGHT,LEFT,CENTER,RIGHT,BELOW_LEFT,BELOW, orBELOW_RIGHT. The default isCENTER.One of the following constants may be added to rotate the label around the label's (x,y) location:
ROTATE_LEFT,ROTATE_RIGHT, orROTATE_AROUND. For example, labelPosition(Plot.LEFT+Plot.ROTATE_LEFT) will rotate each label 90 degrees left and position it to the left of its (x,y) location. The default is no rotation.The following constant may also be added:
PIXEL_COORDINATES. If this constant is omitted, the label's (x,y) location is specified in plot coordinates as determined by the X and Y axes' attributes. If this constant is included, the label's (x,y) location is specified in pixel coordinates relative to the lower left corner of the plot area, regardless of the X and Y axes' attributes.- Parameters:
thePosition- Label positioning.- Returns:
- This plot object.
-
labelOffset
public Plot labelOffset(double theOffset)
Set the offset to use for labels. All labels added hereafter will use the given offset. The default is 0. The offset specifies, in pixel coordinates, how far away from the label's (x,y) location the label is positioned in the direction determined by the label positioning attribute.- Parameters:
theOffset- Label offset.- Returns:
- This plot object.
-
labelFont
public Plot labelFont(java.awt.Font theFont)
Set the font to use for labels. All labels added hereafter will use the given font. The default is sans-serif, plain, 12 point.- Parameters:
theFont- Label offset.- Returns:
- This plot object.
-
labelColor
public Plot labelColor(java.awt.Color theColor)
Set the color to use for labels. All labels added hereafter will use the given color. The default is black.- Parameters:
theColor- Label color.- Returns:
- This plot object.
-
labelBackground
public Plot labelBackground(java.awt.Color theColor)
Set the color to use for label backgrounds. All labels added hereafter will use the given color for the background. The default is transparent.- Parameters:
theColor- Label background color, or null for transparent.- Returns:
- This plot object.
-
label
public Plot label(java.lang.String text, double x, double y)
Add a label to this plot. The label's position is (x,y).The label supports a subset of HTML for specifying attributes of characters. The following HTML tags may be embedded in a label's text:
- <B>Bold</B>
- <I>Italic</I>
- <SUP>Superscript</SUP>
- <SUB>Subscript</SUB>
To get literal less-than, greater-than, and ampersand characters in the text, use the following HTML character entities:
- < -- Less-than (<)
- > -- Greater-than (>)
- & -- Ampersand (&)
- Parameters:
text- Label text.x- X coordinate of label position.y- Y coordinate of label position.- Returns:
- This plot object.
-
draw
public void draw(java.awt.Graphics2D g2d)
Draw this drawable object in the given graphics context. Upon return from this method, the given graphics context's state (color, font, transform, clip, and so on) is the same as it was upon entry to this method.
-
getBoundingBox
public java.awt.geom.Rectangle2D getBoundingBox()
Returns this displayable object's bounding box. This is the smallest rectangle that encloses all of this displayable object.- Specified by:
getBoundingBoxin interfaceDisplayable
-
getBackgroundPaint
public java.awt.Paint getBackgroundPaint()
Returns this displayable object's background paint.- Specified by:
getBackgroundPaintin interfaceDisplayable
-
getFrame
public DisplayableFrame getFrame()
Get a displayable frame in which to view this viewable object. Initially, the returned frame is displaying this viewable object.
-
getTitle
public java.lang.String getTitle()
Get the title for the frame used to view this viewable object. If the title is null, a default title is used.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this plot to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Parameters:
out- Object output stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionRead this plot from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Parameters:
in- Object input stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.java.lang.ClassNotFoundException- Thrown if a class needed to deserialize this plot was not found.
-
write
public static void write(Plot thePlot, java.lang.String theFileName) throws java.io.IOException
Write the given plot to the file with the given name. thePlot is written in serialized form to the file.- Parameters:
thePlot- Plot.theFileName- File name.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
write
public static void write(Plot thePlot, java.io.File theFile) throws java.io.IOException
Write the given plot to the given file. thePlot is written in serialized form to theFile.- Parameters:
thePlot- Plot.theFile- File.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
read
public static Plot read(java.lang.String theFileName) throws java.io.IOException, java.lang.ClassNotFoundException
Read a plot from the file with the given name. The file must contain one instance of class Plot in serialized form; for example, as written by the static Plot.write() method.- Parameters:
theFileName- File name.- Returns:
- Plot.
- Throws:
java.io.IOException- Thrown if an I/O error occurred.java.lang.ClassNotFoundException- Thrown if any class needed to deserialize the plot cannot be found.
-
read
public static Plot read(java.io.File theFile) throws java.io.IOException, java.lang.ClassNotFoundException
Read a plot from the given file. The file must contain one instance of class Plot in serialized form; for example, as written by the static Plot.write() method.- Parameters:
theFile- File.- Returns:
- Plot.
- Throws:
java.io.IOException- Thrown if an I/O error occurred.java.lang.ClassNotFoundException- Thrown if any class needed to deserialize the plot cannot be found.
-
-
DMelt 3.0 © DataMelt by jWork.ORG