Package weka.gui.visualize
Class Plot2D
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- weka.gui.visualize.Plot2D
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible
public class Plot2D extends javax.swing.JPanelThis class plots datasets in two dimensions. It can also plot classifier errors and clusterer predictions.- Version:
- $Revision: 7059 $
- Author:
- Mark Hall (mhall@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intCONST_AUTOMATIC_SHAPEstatic intDEFAULT_SHAPE_SIZEstatic intDIAMOND_SHAPEstatic intERROR_SHAPEstatic intMAX_SHAPESstatic intMISSING_SHAPEstatic intPLUS_SHAPEstatic intTRIANGLEDOWN_SHAPEstatic intTRIANGLEUP_SHAPEstatic intX_SHAPE-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description Plot2D()Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPlot(PlotData2D newPlot)Add a plot to the list of plots to displaydoubleconvertToAttribX(double scx)convert a Panel x coordinate to a raw x value.doubleconvertToAttribY(double scy)convert a Panel y coordinate to a raw y value.doubleconvertToPanelX(double xval)Convert an raw x value to Panel x coordinate.doubleconvertToPanelY(double yval)Convert an raw y value to Panel y coordinate.voiddetermineBounds()Determine the min and max values for axis and colouring attributesPlotData2DgetMasterPlot()Get the master plotdoublegetMaxC()Return the current max value of the colouring attributedoublegetMaxX()Return the current max value of the attribute plotted on the x axisdoublegetMaxY()Return the current max value of the attribute plotted on the y axisdoublegetMinC()Return the current min value of the colouring attributedoublegetMinX()Return the current min value of the attribute plotted on the x axisdoublegetMinY()Return the current min value of the attribute plotted on the y axisFastVectorgetPlots()Return the list of plotsstatic voidmain(java.lang.String[] args)Main method for testing this classvoidpaintComponent(java.awt.Graphics gx)Renders this componentvoidremoveAllPlots()Clears all plotsvoidsearchPoints(int x, int y, boolean newFrame)Pops up a window displaying attribute information on any instances at a point+-plotting_point_size (in panel coordinates)voidsetCindex(int c)Set the index of the attribute to use for colouringvoidsetColours(FastVector cols)Set a list of colours to use when colouring points according to class values or cluster numbersvoidsetInstances(Instances inst)Sets the master plot from a set of instancesvoidsetJitter(int j)Set level of jitter and repaint the plot using the new jitter valuevoidsetMasterPlot(PlotData2D master)Set the master plot.voidsetPlotCompanion(Plot2DCompanion p)Set a companion class.voidsetXindex(int x)Set the index of the attribute to go on the x axisvoidsetYindex(int y)Set the index of the attribute to go on the y axis-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
MAX_SHAPES
public static final int MAX_SHAPES
- See Also:
- Constant Field Values
-
ERROR_SHAPE
public static final int ERROR_SHAPE
- See Also:
- Constant Field Values
-
MISSING_SHAPE
public static final int MISSING_SHAPE
- See Also:
- Constant Field Values
-
CONST_AUTOMATIC_SHAPE
public static final int CONST_AUTOMATIC_SHAPE
- See Also:
- Constant Field Values
-
X_SHAPE
public static final int X_SHAPE
- See Also:
- Constant Field Values
-
PLUS_SHAPE
public static final int PLUS_SHAPE
- See Also:
- Constant Field Values
-
DIAMOND_SHAPE
public static final int DIAMOND_SHAPE
- See Also:
- Constant Field Values
-
TRIANGLEUP_SHAPE
public static final int TRIANGLEUP_SHAPE
- See Also:
- Constant Field Values
-
TRIANGLEDOWN_SHAPE
public static final int TRIANGLEDOWN_SHAPE
- See Also:
- Constant Field Values
-
DEFAULT_SHAPE_SIZE
public static final int DEFAULT_SHAPE_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
setPlotCompanion
public void setPlotCompanion(Plot2DCompanion p)
Set a companion class. This is a class that might want to render something on the plot before we do our thing. Eg, Malcolm's shape drawing stuff needs to happen before we plot axis and points- Parameters:
p- a companion class
-
setJitter
public void setJitter(int j)
Set level of jitter and repaint the plot using the new jitter value- Parameters:
j- the level of jitter
-
setColours
public void setColours(FastVector cols)
Set a list of colours to use when colouring points according to class values or cluster numbers- Parameters:
cols- the list of colours to use
-
setXindex
public void setXindex(int x)
Set the index of the attribute to go on the x axis- Parameters:
x- the index of the attribute to use on the x axis
-
setYindex
public void setYindex(int y)
Set the index of the attribute to go on the y axis- Parameters:
y- the index of the attribute to use on the y axis
-
setCindex
public void setCindex(int c)
Set the index of the attribute to use for colouring- Parameters:
c- the index of the attribute to use for colouring
-
getPlots
public FastVector getPlots()
Return the list of plots- Returns:
- the list of plots
-
getMasterPlot
public PlotData2D getMasterPlot()
Get the master plot- Returns:
- the master plot
-
getMaxX
public double getMaxX()
Return the current max value of the attribute plotted on the x axis- Returns:
- the max x value
-
getMaxY
public double getMaxY()
Return the current max value of the attribute plotted on the y axis- Returns:
- the max y value
-
getMinX
public double getMinX()
Return the current min value of the attribute plotted on the x axis- Returns:
- the min x value
-
getMinY
public double getMinY()
Return the current min value of the attribute plotted on the y axis- Returns:
- the min y value
-
getMaxC
public double getMaxC()
Return the current max value of the colouring attribute- Returns:
- the max colour value
-
getMinC
public double getMinC()
Return the current min value of the colouring attribute- Returns:
- the min colour value
-
setInstances
public void setInstances(Instances inst) throws java.lang.Exception
Sets the master plot from a set of instances- Parameters:
inst- the instances- Throws:
java.lang.Exception- if instances could not be set
-
setMasterPlot
public void setMasterPlot(PlotData2D master) throws java.lang.Exception
Set the master plot.- Parameters:
master- the plot to make the master plot- Throws:
java.lang.Exception- if the plot could not be set.
-
removeAllPlots
public void removeAllPlots()
Clears all plots
-
addPlot
public void addPlot(PlotData2D newPlot) throws java.lang.Exception
Add a plot to the list of plots to display- Parameters:
newPlot- the new plot to add- Throws:
java.lang.Exception- if the plot could not be added
-
searchPoints
public void searchPoints(int x, int y, boolean newFrame)Pops up a window displaying attribute information on any instances at a point+-plotting_point_size (in panel coordinates)- Parameters:
x- the x value of the clicked pointy- the y value of the clicked pointnewFrame- true if instance info is to be displayed in a new frame.
-
determineBounds
public void determineBounds()
Determine the min and max values for axis and colouring attributes
-
convertToAttribX
public double convertToAttribX(double scx)
convert a Panel x coordinate to a raw x value.- Parameters:
scx- The Panel x coordinate- Returns:
- A raw x value.
-
convertToAttribY
public double convertToAttribY(double scy)
convert a Panel y coordinate to a raw y value.- Parameters:
scy- The Panel y coordinate- Returns:
- A raw y value.
-
convertToPanelX
public double convertToPanelX(double xval)
Convert an raw x value to Panel x coordinate.- Parameters:
xval- the raw x value- Returns:
- an x value for plotting in the panel.
-
convertToPanelY
public double convertToPanelY(double yval)
Convert an raw y value to Panel y coordinate.- Parameters:
yval- the raw y value- Returns:
- an y value for plotting in the panel.
-
paintComponent
public void paintComponent(java.awt.Graphics gx)
Renders this component- Parameters:
gx- the graphics context
-
main
public static void main(java.lang.String[] args)
Main method for testing this class- Parameters:
args- arguments
-
-