Java Statistical Classes

jsc.swt.plot2d
Class PdfPlot

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--jsc.swt.plot2d.PlotPanel
                                |
                                +--jsc.swt.plot2d.AxesPlot
                                      |
                                      +--jsc.swt.plot2d.FunctionPlot2D
                                            |
                                            +--jsc.swt.plot2d.PdfPlot
All Implemented Interfaces:
Accessible, Cloneable, ImageObserver, MenuContainer, PlotFunction, Serializable

public class PdfPlot
extends FunctionPlot2D
implements PlotFunction, Cloneable

This class represents a plot of probability density functions. Methods are provided for adding any number of curves or bars representing continuous or discrete distributions respectively. Bars representing normalized frequency data can also be added to the plot.

Version:
1.0
Author:
A. J. Bertie.
See Also:
Serialized Form

Field Summary
 
Fields inherited from class jsc.swt.plot2d.AxesPlot
horizontalAxis, title, verticalAxis
 
Fields inherited from class jsc.swt.plot2d.PlotPanel
componentBounds, hints, objects, SEE_THRU, virtualSpace, vt
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PdfPlot(AxisModel horizontalAxisModel, AxisModel verticalAxisModel, String title)
          Creates the plot with given title and AxisModel objects.
 
Method Summary
 PlotShape addBars(FrequencyTable freq, Color colour, Paint paint, Stroke stroke, boolean filled)
          Add a set of bars to the plot.
 PlotShape addBars(FrequencyTable freq, Color colour, Stroke stroke)
          Add a set of bars to the plot.
 PlotShape addBars(FrequencyTable freq, Paint paint)
          Add a set of bars to the plot.
 PlotShape addBars(Tally tally, double barWidth, Color colour, Paint paint, boolean drawLines, double offset)
          Add a set of bars to the plot.
 PlotShape addPdf(Distribution d, double xMin, double xMax, int n, Color colour, boolean filled)
          Add the curve of pdf(x) of a continuous distribution to the plot.
 PlotShape addPdf(Distribution d, double xMin, double xMax, int n, Color colour, Stroke stroke)
          Add the curve of pdf(x) of a continuous distribution to the plot.
 PlotShape addPdf(Distribution d, double xMin, double xMax, int n, Color colour, Stroke stroke, Paint paint, boolean filled)
          Add the curve of pdf(x) of a continuous distribution to the plot.
 PlotShape addPdf(Distribution d, int n, Color colour)
          Add the pdf curve of distribution d to the plot.
 PlotShape addPdf(Distribution d, int n, Color colour, Stroke stroke)
          Add the pdf curve of distribution d to the plot.
 PlotShape addPmf(Distribution d, int n, double xMin, double xStep, double barWidth, Color colour, Paint paint, boolean drawLines)
          Add the pmf bars of discrete distribution d to the plot.
 PlotShape addPmf(Distribution d, int n, double xMin, double xStep, double barWidth, Color colour, Paint paint, boolean drawLines, double offset)
          Add the pmf bars of discrete distribution d to the plot.
 PlotShape addPmf(Distribution d, int xMin, int xMax, double barWidth, Color colour, Paint paint, boolean drawLines)
          Add the pmf bars of discrete distribution d to the plot.
 double getOrdinate(double x)
          Returns y = f(x).
 
Methods inherited from class jsc.swt.plot2d.FunctionPlot2D
addFunction, addFunction, addFunction, addFunction, addFunction, addFunction
 
Methods inherited from class jsc.swt.plot2d.AxesPlot
addVerticalLine, addVerticalLine, clone, copy, getHorizontalAxis, getTitle, getVerticalAxis, outsideAxes, paintComponent, rescaleHorizontal, rescaleVertical, setClipping, setPaintXaxis, setPaintYaxis, setTitle
 
Methods inherited from class jsc.swt.plot2d.PlotPanel
addComponent, addComponent, addObject, addObjects, addRenderingHint, copyContents, copyPlot, ensureComponentCapacity, ensureObjectCapacity, getBufferedImage, getComponentBounds, getComponentBounds, getObject, getObject, getObjectCount, getObjectIndex, getObjects, getParHeight, getParWidth, getRenderingHints, getVirtualSpace, getVirtualTransform, isAntialiased, isEmpty, isTextAntialiased, merge, paintBackground, pixelToVirtual, pixelToVirtual, removeAll, removeAllComponents, removeAllObjects, removeComponent, removeLastComponent, removeLastObject, removeObject, removeObject, removeRenderingHint, setAntialiasing, setComponentBounds, setComponentBounds, setFocusColour, setObjectComposite, setTextAntialiasing, setVirtualSpace, setZoomable, setZoomBoxColour, setZoomBoxStroke, virtualToPixel, virtualToPixel, virtualToPixelHeight, virtualToPixelWidth, write, write
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PdfPlot

public PdfPlot(AxisModel horizontalAxisModel,
               AxisModel verticalAxisModel,
               String title)
Creates the plot with given title and AxisModel objects. The axes meet at their minimum values.

Parameters:
horizontalAxisModel - the horizontal axis model.
verticalAxisModel - the vertical axis model.
title - the title of the plot.
Method Detail

addBars

public PlotShape addBars(FrequencyTable freq,
                         Paint paint)
Add a set of bars to the plot. The bar heights are proportional to the normalized frequencies in the specified table, and drawn as a filled polygon using the specified paint style (which can be a Color object). Redraws the whole plot. Returns the PlotShape that was added to the plot.

Parameters:
freq - the table of frequencies.
paint - the paint style if the bars are filled.
Returns:
the object added to the plot.

addBars

public PlotShape addBars(FrequencyTable freq,
                         Color colour,
                         Stroke stroke)
Add a set of bars to the plot. The bar heights are proportional to the normalized frequencies in the specified table, and their outline is drawn as a polygon using the specified graphical attributes. Redraws the whole plot. Returns the PlotShape that was added to the plot.

Parameters:
freq - the table of frequencies.
colour - the colour of the bars.
stroke - the stroke style if bars are not filled.
Returns:
the object added to the plot.

addBars

public PlotShape addBars(FrequencyTable freq,
                         Color colour,
                         Paint paint,
                         Stroke stroke,
                         boolean filled)
Add a set of bars to the plot. The bar heights are proportional to the normalized frequencies in the specified table, and drawn as a polygon using the specified graphical attributes. Redraws the whole plot. Returns the PlotShape that was added to the plot.

Parameters:
freq - the table of frequencies.
colour - the colour of the bars.
paint - the paint style if the bars are filled.
stroke - the stroke style if bars are not filled.
filled - if true, the bars are a filled; otherwise the outline of the bars is drawn.
Returns:
the object added to the plot.

addBars

public PlotShape addBars(Tally tally,
                         double barWidth,
                         Color colour,
                         Paint paint,
                         boolean drawLines,
                         double offset)
Add a set of bars to the plot. The bar heights are proportional to the proportions in the tally object, and are drawn using the specified graphical attributes.

If drawLines is true, the bars are drawn as lines using the given colour and bar width in device (pixel) coordinates. If drawLines is false, the bars are drawn as rectangles using the given bar width in virtual coordinates (usually 1.0 or less) and paint style.

The offset parameter is provided for the case where several sets of bars are added to the plot, and the bars from different sets need to be viewed alongside each other rather than superimposed. For example, if two sets of bars are added, the barWidth could be set to 0.5 in both cases, and offset set to -0.25 and +0.25 to separate the bars at each x-value.

Redraws the plot. Returns the PlotShape that was added to the plot.

Parameters:
tally - the table of frequencies.
barWidth - the width of each bar in pixels if drawLines is true; in virtual co-ordinates if drawLines is false.
colour - the colour of the bars.
paint - the paint style of rectangular bars.
drawLines - if true, the bars are drawn as lines; otherwise the bars are drawn as rectangles.
offset - the horizontal virtual offset distance.
Returns:
the object added to the plot.

addPdf

public PlotShape addPdf(Distribution d,
                        int n,
                        Color colour)
Add the pdf curve of distribution d to the plot. The curve is drawn over the entire extent of the horizontal axis using straight lines connecting n points, and the specified colour. The stroke style is set to the current default of PlotShape.

Parameters:
d - a continuous distribution.
n - the number of points used to draw the curve.
colour - the colour of the curve.
Returns:
the object added to the plot.

addPdf

public PlotShape addPdf(Distribution d,
                        int n,
                        Color colour,
                        Stroke stroke)
Add the pdf curve of distribution d to the plot. The curve is drawn over the entire extent of the horizontal axis using straight lines connecting n points, and the specified colour and stroke style.

Parameters:
d - a continuous distribution.
n - the number of points used to draw the curve.
colour - the colour of the curve.
stroke - the stroke style of the curve.
Returns:
the object added to the plot.

addPdf

public PlotShape addPdf(Distribution d,
                        double xMin,
                        double xMax,
                        int n,
                        Color colour,
                        boolean filled)
Add the curve of pdf(x) of a continuous distribution to the plot. The curve is plotted at n values of x from xMin to xMax using straight lines connecting the points, and the specified colour. The stroke style is set to the current default of PlotShape.

If filled is true, the area under the curve from xMin to xMax is filled using the specified colour.

Redraws the plot. Returns the PlotShape that was added to the plot.

Parameters:
d - a continuous distribution.
xMin - the minimum x value.
xMax - the maximum x value.
n - the number of points used to draw the curve.
colour - the colour of the curve.
filled - if true, the area under the curve is filled.
Returns:
the object added to the plot.

addPdf

public PlotShape addPdf(Distribution d,
                        double xMin,
                        double xMax,
                        int n,
                        Color colour,
                        Stroke stroke)
Add the curve of pdf(x) of a continuous distribution to the plot. The curve is plotted at n values of x from xMin to xMax using straight lines connecting the points, and the specified colour and stroke style. Redraws the plot. Returns the PlotShape that was added to the plot.

Parameters:
d - a continuous distribution.
xMin - the minimum x value.
xMax - the maximum x value.
n - the number of points used to draw the curve.
colour - the colour of the curve.
stroke - the stroke style of the curve.
Returns:
the object added to the plot.

addPdf

public PlotShape addPdf(Distribution d,
                        double xMin,
                        double xMax,
                        int n,
                        Color colour,
                        Stroke stroke,
                        Paint paint,
                        boolean filled)
Add the curve of pdf(x) of a continuous distribution to the plot. The curve is plotted at n values of x from xMin to xMax using straight lines connecting the points, and the specified colour and stroke style.

If filled is true, the area under the curve from xMin to xMax is filled using the specified paint style.

Redraws the plot. Returns the PlotShape that was added to the plot.

Parameters:
d - a continuous distribution.
xMin - the minimum x value.
xMax - the maximum x value.
n - the number of points used to draw the curve.
colour - the colour of the curve.
stroke - the stroke style of the curve.
paint - the paint style used to fill under the curve.
filled - if true, the area under the curve is filled.
Returns:
the object added to the plot.

addPmf

public PlotShape addPmf(Distribution d,
                        int xMin,
                        int xMax,
                        double barWidth,
                        Color colour,
                        Paint paint,
                        boolean drawLines)
Add the pmf bars of discrete distribution d to the plot. The bars are drawn at each integer value from xMin to xMax using the specified graphic attributes.

If drawLines is true, the bars are drawn as lines using the given colour and bar width in device (pixel) coordinates. If drawLines is false, the bars are drawn as rectangles using the given bar width in virtual coordinates (usually 1.0 or less) and paint style.

Redraws the plot. Returns the PlotShape that was added to the plot.

Parameters:
d - a discrete distribution.
xMin - the minimum x value.
xMax - the maximum x value.
barWidth - the width of each bar in pixels if drawLines is true; in virtual co-ordinates if drawLines is false.
colour - the colour of the bars.
paint - the paint style of rectangular bars.
drawLines - if true, the bars are drawn as lines; otherwise the bars are drawn as rectangles.
Returns:
the object added to the plot.

addPmf

public PlotShape addPmf(Distribution d,
                        int n,
                        double xMin,
                        double xStep,
                        double barWidth,
                        Color colour,
                        Paint paint,
                        boolean drawLines)
Add the pmf bars of discrete distribution d to the plot. n bars are drawn at positions xMin, xMin+xStep, etc. on the horizontal axis, using the specified graphic attributes.

If drawLines is true, the bars are drawn as lines using the given colour and bar width in device (pixel) coordinates. If drawLines is false, the bars are drawn as rectangles using the given bar width in virtual coordinates (usually 1.0 or less) and paint style.

Redraws the plot. Returns the PlotShape that was added to the plot.

Parameters:
d - a discrete distribution.
n - the number of bars.
xMin - the minimum x value.
xStep - the step distance.
barWidth - the width of each bar in pixels if drawLines is true; in virtual co-ordinates if drawLines is false.
colour - the colour of the bars.
paint - the paint style of rectangular bars.
drawLines - if true, the bars are drawn as lines; otherwise the bars are drawn as rectangles.
Returns:
the object added to the plot.

addPmf

public PlotShape addPmf(Distribution d,
                        int n,
                        double xMin,
                        double xStep,
                        double barWidth,
                        Color colour,
                        Paint paint,
                        boolean drawLines,
                        double offset)
Add the pmf bars of discrete distribution d to the plot. n bars are drawn at positions xMin, xMin+xStep, etc. on the horizontal axis, using the specified graphic attributes.

If drawLines is true, the bars are drawn as lines using the given colour and bar width in device (pixel) coordinates. If drawLines is false, the bars are drawn as rectangles using the given bar width in virtual coordinates (usually 1.0 or less) and paint style.

The offset argument is provided for the case where several sets of pmf bars are added to the plot, and the bars of the different distributions need to be viewed alongside each other rather than superimposed. For example, if bars for two distributions are added, the barWidth could be set to 0.5 in both cases, and offset set to -0.25 and +0.25 to separate the bars at each x-value.

Redraws the plot. Returns the PlotShape that was added to the plot.

Parameters:
d - a discrete distribution.
n - the number of bars.
xMin - the minimum x value.
xStep - the step distance.
barWidth - the width of each bar in pixels if drawLines is true; in virtual co-ordinates if drawLines is false.
colour - the colour of the bars.
paint - the paint style of rectangular bars.
drawLines - if true, the bars are drawn as lines; otherwise the bars are drawn as rectangles.
offset - the horizontal virtual offset distance.
Returns:
the object added to the plot.

getOrdinate

public double getOrdinate(double x)
Description copied from interface: PlotFunction
Returns y = f(x). The method should return Double.NaN if f(x) cannot be calculated at x.

Specified by:
getOrdinate in interface PlotFunction
Parameters:
x - the value of x.
Returns:
the value of f(x), or Double.NaN if f(x) does not exist.

Java Statistical Classes

Copyright © Andrew James Bertie, 2005, all rights reserved. Updated 12th Aug 2005