public class PlotCanvas
extends javax.swing.JPanel
For both 2D and 3D plot, the user can zoom in/out by mouse wheel. For 2D plot, the user can shift the coordinates by moving mouse after double click. The user can also select an area by mouse for detailed view. For 3D plot, the user can rotate the view by dragging mouse.
javax.swing.JPanel.AccessibleJPanel
javax.swing.JComponent.AccessibleJComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
PlotCanvas(double[] lowerBound,
double[] upperBound)
Constructor
|
PlotCanvas(double[] lowerBound,
double[] upperBound,
boolean extendBound)
Constructor
|
PlotCanvas(double[] lowerBound,
double[] upperBound,
java.lang.String[] axisLabels)
Constructor
|
PlotCanvas(double[] lowerBound,
double[] upperBound,
java.lang.String[] axisLabels,
boolean extendBound)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
add(Plot p)
Add a graphical shape to the canvas.
|
void |
add(Shape p)
Add a graphical shape to the canvas.
|
void |
clear()
Remove all graphic plots from the canvas.
|
void |
extendBound(double[] lowerBound,
double[] upperBound)
Extend lower and upper bounds.
|
void |
extendLowerBound(double[] bound)
Extend lower bounds.
|
void |
extendUpperBound(double[] bound)
Extend upper bounds.
|
Axis |
getAxis(int i)
Returns the i-th axis.
|
java.lang.String |
getAxisLabel(int axis)
Returns the label/legend of an axis.
|
java.lang.String[] |
getAxisLabels()
Returns the labels/legends of axes.
|
Base |
getBase()
Returns the coordinate base.
|
double[] |
getLowerBounds()
Returns the lower bounds.
|
double |
getMargin()
Returns the size of margin, which is not used as plot area.
|
java.util.List<Shape> |
getShapes()
Returns the list of shapes in the canvas.
|
java.lang.String |
getTitle()
Returns the main title of canvas.
|
java.awt.Color |
getTitleColor()
Returns the color for title.
|
java.awt.Font |
getTitleFont()
Returns the font for title.
|
javax.swing.JComponent |
getToolbar()
Returns a tool bar to control the plot.
|
double[] |
getUpperBounds()
Returns the upper bounds.
|
Grid |
grid(double[][][] data)
Adds a 2D grid plot to the canvas.
|
Histogram |
histogram(double[] data,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(double[] data,
double[] breaks,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(double[] data,
int k,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(int[] data,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(int[] data,
double[] breaks,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(int[] data,
int k,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(java.lang.String id,
double[] data,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(java.lang.String id,
double[] data,
double[] breaks,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(java.lang.String id,
double[] data,
int k,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(java.lang.String id,
int[] data,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(java.lang.String id,
int[] data,
double[] breaks,
java.awt.Color color)
Adds a histogram to this canvas.
|
Histogram |
histogram(java.lang.String id,
int[] data,
int k,
java.awt.Color color)
Adds a histogram to this canvas.
|
void |
label(java.lang.String text,
java.awt.Color color,
double... coord)
Adds a label to this canvas.
|
void |
label(java.lang.String text,
double... coord)
Adds a label to this canvas.
|
void |
label(java.lang.String text,
java.awt.Font font,
java.awt.Color color,
double... coord)
Adds a label to this canvas.
|
void |
label(java.lang.String text,
java.awt.Font font,
double... coord)
Adds a label to this canvas.
|
LinePlot |
line(double[]... data)
Adds a poly line plot to this canvas.
|
LinePlot |
line(double[] y)
Adds a poly line plot to this canvas.
|
LinePlot |
line(double[][] data,
java.awt.Color color)
Adds a poly line plot to this canvas.
|
LinePlot |
line(double[][] data,
Line.Style style)
Adds a poly line plot to this canvas.
|
LinePlot |
line(double[][] data,
Line.Style style,
java.awt.Color color)
Adds a poly line plot to this canvas.
|
LinePlot |
line(double[] y,
java.awt.Color color)
Adds a poly line plot to this canvas.
|
LinePlot |
line(double[] y,
Line.Style style)
Add a poly line plot of given data into the current canvas.
|
LinePlot |
line(double[] y,
Line.Style style,
java.awt.Color color)
Adds a poly line plot to this canvas.
|
LinePlot |
line(java.lang.String id,
double[]... data)
Adds a poly line plot to this canvas.
|
LinePlot |
line(java.lang.String id,
double[] y)
Adds a poly line plot to this canvas.
|
LinePlot |
line(java.lang.String id,
double[][] data,
java.awt.Color color)
Adds a poly line plot to this canvas.
|
LinePlot |
line(java.lang.String id,
double[][] data,
Line.Style style)
Adds a poly line plot to this canvas.
|
LinePlot |
line(java.lang.String id,
double[][] data,
Line.Style style,
java.awt.Color color)
Adds a poly line plot to this canvas.
|
LinePlot |
line(java.lang.String id,
double[] y,
java.awt.Color color)
Adds a poly line plot to this canvas.
|
LinePlot |
line(java.lang.String id,
double[] y,
Line.Style style)
Adds a poly line plot to this canvas.
|
LinePlot |
line(java.lang.String id,
double[] y,
Line.Style style,
java.awt.Color color)
Add a poly line plot of given data into the current canvas.
|
void |
point(char legend,
java.awt.Color color,
double... coord)
Adds a point to this canvas.
|
void |
point(char legend,
double... coord)
Adds a point to this canvas.
|
void |
point(java.awt.Color color,
double... coord)
Adds a point to this canvas.
|
void |
point(double... coord)
Adds a point to this canvas.
|
ScatterPlot |
points(double[]... data)
Adds a scatter plot to this canvas.
|
ScatterPlot |
points(double[][] data,
char legend)
Adds a scatter plot to this canvas.
|
ScatterPlot |
points(double[][] data,
char legend,
java.awt.Color color)
Adds a scatter plot to this canvas.
|
ScatterPlot |
points(double[][] data,
java.awt.Color color)
Adds a scatter plot to this canvas.
|
ScatterPlot |
points(double[][] data,
java.lang.String[] labels)
Adds a scatter plot to this canvas.
|
ScatterPlot |
points(java.lang.String id,
double[]... data)
Adds a scatter plot to this canvas.
|
ScatterPlot |
points(java.lang.String id,
double[][] data,
char legend)
Adds a scatter plot to this canvas.
|
ScatterPlot |
points(java.lang.String id,
double[][] data,
char legend,
java.awt.Color color)
Adds a scatter plot to this canvas.
|
ScatterPlot |
points(java.lang.String id,
double[][] data,
java.awt.Color color)
Adds a scatter plot to this canvas.
|
ScatterPlot |
points(java.lang.String id,
double[][] data,
java.lang.String[] labels)
Adds a scatter plot to this canvas.
|
void |
print()
Prints the plot.
|
void |
remove(Plot p)
Remove a graphical shape from the canvas.
|
void |
remove(Shape p)
Remove a graphical shape from the canvas.
|
void |
reset()
Resets the plot.
|
void |
save()
Shows a file chooser and exports the plot to the selected image file.
|
void |
save(java.io.File file)
Exports the plot to an image file.
|
static PlotCanvas |
screeplot(smile.projection.PCA pca)
Create a scree plot for PCA.
|
PlotCanvas |
setAxisLabel(int axis,
java.lang.String label)
Sets the label/legend of an axis.
|
PlotCanvas |
setAxisLabels(java.lang.String... labels)
Sets the labels/legends of axes.
|
PlotCanvas |
setMargin(double margin)
Sets the size of margin in [0.0, 0.3] on each side.
|
PlotCanvas |
setTitle(java.lang.String title)
Set the main title of canvas.
|
PlotCanvas |
setTitleColor(java.awt.Color color)
Set the color for title.
|
PlotCanvas |
setTitleFont(java.awt.Font font)
Set the font for title.
|
StaircasePlot |
staircase(double[][] data,
java.awt.Color color)
Adds a staircase line plot to this canvas.
|
StaircasePlot |
staircase(java.lang.String id,
double[][] data,
java.awt.Color color)
Adds a staircase line plot to this canvas.
|
void |
zoom(boolean inout)
Zooms in/out the plot.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
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, firePropertyChange, 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, getPeer, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public PlotCanvas(double[] lowerBound, double[] upperBound)
public PlotCanvas(double[] lowerBound, double[] upperBound, boolean extendBound)
public PlotCanvas(double[] lowerBound, double[] upperBound, java.lang.String[] axisLabels)
public PlotCanvas(double[] lowerBound, double[] upperBound, java.lang.String[] axisLabels, boolean extendBound)
public javax.swing.JComponent getToolbar()
public void save() throws java.io.IOException
java.io.IOException
- if an error occurs during writing.public void save(java.io.File file) throws java.io.IOException
file
- the destination file.java.io.IOException
- if an error occurs during writing.public void print()
public void zoom(boolean inout)
inout
- true if zoom in. Otherwise, zoom out.public void reset()
public double getMargin()
public PlotCanvas setMargin(double margin)
margin
- the size of margin.public Base getBase()
public java.lang.String getTitle()
public PlotCanvas setTitle(java.lang.String title)
public java.awt.Font getTitleFont()
public java.awt.Color getTitleColor()
public PlotCanvas setTitleFont(java.awt.Font font)
public PlotCanvas setTitleColor(java.awt.Color color)
public Axis getAxis(int i)
public java.lang.String[] getAxisLabels()
public java.lang.String getAxisLabel(int axis)
public PlotCanvas setAxisLabels(java.lang.String... labels)
public PlotCanvas setAxisLabel(int axis, java.lang.String label)
public java.util.List<Shape> getShapes()
public void add(Shape p)
public void remove(Shape p)
public void add(Plot p)
public void remove(Plot p)
public void clear()
public double[] getLowerBounds()
public double[] getUpperBounds()
public void extendLowerBound(double[] bound)
public void extendUpperBound(double[] bound)
public void extendBound(double[] lowerBound, double[] upperBound)
public void label(java.lang.String text, double... coord)
public void label(java.lang.String text, java.awt.Font font, double... coord)
public void label(java.lang.String text, java.awt.Color color, double... coord)
public void label(java.lang.String text, java.awt.Font font, java.awt.Color color, double... coord)
public void point(double... coord)
public void point(char legend, double... coord)
public void point(java.awt.Color color, double... coord)
public void point(char legend, java.awt.Color color, double... coord)
public ScatterPlot points(double[]... data)
data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.public ScatterPlot points(java.lang.String id, double[]... data)
id
- the id of the plot.data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.public ScatterPlot points(double[][] data, java.lang.String[] labels)
data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.labels
- labels of points.public ScatterPlot points(java.lang.String id, double[][] data, java.lang.String[] labels)
id
- the id of the plot.data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.labels
- labels of points.public ScatterPlot points(double[][] data, char legend)
data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.legend
- the legend used to draw points.
public ScatterPlot points(java.lang.String id, double[][] data, char legend)
id
- the id of the plot.data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.legend
- the legend used to draw points.
public ScatterPlot points(double[][] data, java.awt.Color color)
data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.color
- the color used to draw points.public ScatterPlot points(java.lang.String id, double[][] data, java.awt.Color color)
id
- the id of the plot.data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.color
- the color used to draw points.public ScatterPlot points(double[][] data, char legend, java.awt.Color color)
data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.color
- the color used to draw points.legend
- the legend used to draw points.
public ScatterPlot points(java.lang.String id, double[][] data, char legend, java.awt.Color color)
id
- the id of the plot.data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.color
- the color used to draw points.legend
- the legend used to draw points.
public LinePlot line(double[] y)
y
- a data vector that describes y coordinates of points. The x
coordinates will be [0, n), where n is the length of y.public LinePlot line(java.lang.String id, double[] y)
id
- the id of the plot.y
- a data vector that describes y coordinates of points. The x
coordinates will be [0, n), where n is the length of y.public LinePlot line(double[] y, java.awt.Color color)
y
- a data vector that describes y coordinates of points. The x
coordinates will be [0, n), where n is the length of y.color
- the color of line.public LinePlot line(java.lang.String id, double[] y, java.awt.Color color)
id
- the id of the plot.y
- a data vector that describes y coordinates of points. The x
coordinates will be [0, n), where n is the length of y.color
- the color of line.public LinePlot line(double[] y, Line.Style style)
y
- a data vector that describes y coordinates of points. The x
coordinates will be [0, n), where n is the length of y.style
- the stroke style of line.public LinePlot line(java.lang.String id, double[] y, Line.Style style)
id
- the id of the plot.y
- a data vector that describes y coordinates of points. The x
coordinates will be [0, n), where n is the length of y.style
- the stroke style of line.public LinePlot line(double[] y, Line.Style style, java.awt.Color color)
y
- a data vector that describes y coordinates of points. The x
coordinates will be [0, n), where n is the length of y.style
- the stroke style of line.color
- the color of line.public LinePlot line(java.lang.String id, double[] y, Line.Style style, java.awt.Color color)
id
- the id of the plot.y
- a data vector that describes y coordinates of points. The x
coordinates will be [0, n), where n is the length of y.style
- the stroke style of line.color
- the color of line.public LinePlot line(double[]... data)
data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.public LinePlot line(java.lang.String id, double[]... data)
id
- the id of the plot.data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.public LinePlot line(double[][] data, java.awt.Color color)
data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.color
- the color of line.public LinePlot line(java.lang.String id, double[][] data, java.awt.Color color)
id
- the id of the plot.data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.color
- the color of line.public LinePlot line(double[][] data, Line.Style style)
data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.style
- the stroke style of line.public LinePlot line(java.lang.String id, double[][] data, Line.Style style)
id
- the id of the plot.data
- a n-by-2 or n-by-3 matrix that describes coordinates of points.style
- the stroke style of line.public LinePlot line(double[][] data, Line.Style style, java.awt.Color color)
data
- a n x 2 or n x 3 matrix that describes coordinates of points.style
- the stroke style of line.color
- the color of line.public LinePlot line(java.lang.String id, double[][] data, Line.Style style, java.awt.Color color)
id
- the id of the plot.data
- a n x 2 or n x 3 matrix that describes coordinates of points.style
- the stroke style of line.color
- the color of line.public StaircasePlot staircase(double[][] data, java.awt.Color color)
data
- a n x 2 or n x 3 matrix that describes coordinates of points.color
- the color of line.public StaircasePlot staircase(java.lang.String id, double[][] data, java.awt.Color color)
id
- the id of the plot.data
- a n x 2 or n x 3 matrix that describes coordinates of points.color
- the color of line.public Histogram histogram(double[] data, java.awt.Color color)
data
- a sample set.public Histogram histogram(java.lang.String id, double[] data, java.awt.Color color)
id
- the id of the plot.data
- a sample set.public Histogram histogram(double[] data, int k, java.awt.Color color)
data
- a sample set.k
- the number of bins.public Histogram histogram(java.lang.String id, double[] data, int k, java.awt.Color color)
id
- the id of the plot.data
- a sample set.k
- the number of bins.public Histogram histogram(double[] data, double[] breaks, java.awt.Color color)
data
- a sample set.breaks
- an array of size k+1 giving the breakpoints between
histogram cells. Must be in ascending order.public Histogram histogram(java.lang.String id, double[] data, double[] breaks, java.awt.Color color)
id
- the id of the plot.data
- a sample set.breaks
- an array of size k+1 giving the breakpoints between
histogram cells. Must be in ascending order.public Histogram histogram(int[] data, java.awt.Color color)
data
- a sample set.public Histogram histogram(java.lang.String id, int[] data, java.awt.Color color)
id
- the id of the plot.data
- a sample set.public Histogram histogram(int[] data, int k, java.awt.Color color)
data
- a sample set.k
- the number of bins.public Histogram histogram(java.lang.String id, int[] data, int k, java.awt.Color color)
id
- the id of the plot.data
- a sample set.k
- the number of bins.public Histogram histogram(int[] data, double[] breaks, java.awt.Color color)
data
- a sample set.breaks
- an array of size k+1 giving the breakpoints between
histogram cells. Must be in ascending order.public Histogram histogram(java.lang.String id, int[] data, double[] breaks, java.awt.Color color)
id
- the id of the plot.data
- a sample set.breaks
- an array of size k+1 giving the breakpoints between
histogram cells. Must be in ascending order.public Grid grid(double[][][] data)
data
- an m x n x 2 array which are coordinates of m x n grid.public static PlotCanvas screeplot(smile.projection.PCA pca)
pca
- principal component analysis object.