Package smile.plot.swing
Class Figure
java.lang.Object
smile.plot.swing.Figure
A figure serves as the canvas on which plots and other elements are drawn.
It can be conceptualized as the top-level container holding all plot
elements, including axes, titles, legends, and annotations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a graphical shape to the canvas.void
Adds a graphical shape to the canvas.void
Add a PropertyChangeListener to the listener list.void
clear()
Removes all graphic plots from the canvas.void
extendBound
(double[] lowerBound, double[] upperBound) Extends the lower and upper bounds.void
extendLowerBound
(double[] bound) Extends the lower bounds.void
extendUpperBound
(double[] bound) Extends the upper bounds.getAxis
(int i) Returns the i-th axis.getAxisLabel
(int i) Returns the label/legend of an axis.String[]
Returns the labels/legends of axes.double[]
Returns the lower bounds.double
Returns the size of margin, which is not used as plot area.Returns an array of all the listeners that were added to the PropertyChangeSupport object with addPropertyChangeListener().Returns the list of shapes in the canvas.getTitle()
Returns the main title of figure.Returns the color for title.Returns the font for title.double[]
Returns the upper bounds.boolean
Returns true if legends are visible.void
Paints the figure.projection
(int width, int height) Returns a projection of the figure.void
Removes a graphical shape from the canvas.void
Removes a graphical shape from the canvas.void
Remove a PropertyChangeListener from the listener list.setAxisLabel
(int i, String label) Sets the label/legend of an axis.setAxisLabels
(String... labels) Sets the labels/legends of axes.void
setBound
(double[] lowerBound, double[] upperBound) Sets the lower and upper bounds.setLegendVisible
(boolean visible) Sets if legends are visible.setMargin
(double margin) Sets the size of margin in [0.0, 0.3] on each side.Sets the main title of figure.setTitleColor
(Color color) Sets the color for title.setTitleFont
(Font font) Sets the font for title.show()
Shows the plot in a window.toBufferedImage
(int width, int height) Exports the figure to an image.
-
Constructor Details
-
Figure
public Figure(double[] lowerBound, double[] upperBound) Constructor.- Parameters:
lowerBound
- the lower bound of base.upperBound
- the upper bound of base.
-
Figure
public Figure(double[] lowerBound, double[] upperBound, boolean extendBound) Constructor.- Parameters:
lowerBound
- the lower bound of base.upperBound
- the upper bound of base.extendBound
- true if extending the bounds for padding.
-
-
Method Details
-
addPropertyChangeListener
Add a PropertyChangeListener to the listener list. The listener is registered for all properties. The same listener object may be added more than once, and will be called as many times as it is added. If listener is null, no exception is thrown and no action is taken.- Parameters:
listener
- a property change listener.
-
removePropertyChangeListener
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties. If listener was added more than once to the same event source, it will be notified one less time after being removed. If listener is null, or was never added, no exception is thrown and no action is taken.- Parameters:
listener
- a property change listener.
-
getPropertyChangeListeners
Returns an array of all the listeners that were added to the PropertyChangeSupport object with addPropertyChangeListener().- Returns:
- the registered property change listeners.
-
projection
Returns a projection of the figure.- Parameters:
width
- the canvas width.height
- the canvas height.- Returns:
- a projection of the figure.
-
toBufferedImage
Exports the figure to an image.- Parameters:
width
- the width of image.height
- the height of image.- Returns:
- the image of figure.
-
isLegendVisible
public boolean isLegendVisible()Returns true if legends are visible.- Returns:
- true if legends are visible.
-
setLegendVisible
Sets if legends are visible.- Parameters:
visible
- the flag if legends are visible.- Returns:
- this object.
-
getMargin
public double getMargin()Returns the size of margin, which is not used as plot area. Currently, all four sides have the same margin size.- Returns:
- the size of margin.
-
setMargin
Sets the size of margin in [0.0, 0.3] on each side. Currently, all four sides have the same margin size.- Parameters:
margin
- the size of margin.- Returns:
- this object.
-
getTitle
Returns the main title of figure.- Returns:
- the main title of figure.
-
setTitle
Sets the main title of figure.- Parameters:
title
- the main title of figure.- Returns:
- this object.
-
getTitleFont
Returns the font for title.- Returns:
- the font for title.
-
setTitleFont
Sets the font for title.- Parameters:
font
- the font for title.- Returns:
- this object.
-
getTitleColor
Returns the color for title.- Returns:
- the color for title.
-
setTitleColor
Sets the color for title.- Parameters:
color
- the color for title.- Returns:
- this object.
-
getAxis
Returns the i-th axis.- Parameters:
i
- the index of axis.- Returns:
- the i-th axis.
-
getAxisLabels
Returns the labels/legends of axes.- Returns:
- the labels/legends of axes.
-
getAxisLabel
Returns the label/legend of an axis.- Parameters:
i
- the index of axis.- Returns:
- the label/legend of an axis.
-
setAxisLabels
Sets the labels/legends of axes.- Parameters:
labels
- the labels/legends of axes.- Returns:
- this object.
-
setAxisLabel
Sets the label/legend of an axis.- Parameters:
i
- the index of axis.label
- the label/legend of axes.- Returns:
- this object.
-
getShapes
Returns the list of shapes in the canvas.- Returns:
- the list of shapes in the canvas.
-
add
Adds a graphical shape to the canvas.- Parameters:
p
- the shape.
-
remove
Removes a graphical shape from the canvas.- Parameters:
p
- the shape.
-
add
Adds a graphical shape to the canvas.- Parameters:
p
- the plot.
-
remove
Removes a graphical shape from the canvas.- Parameters:
p
- the plot.
-
clear
public void clear()Removes all graphic plots from the canvas. -
getLowerBounds
public double[] getLowerBounds()Returns the lower bounds.- Returns:
- the lower bounds.
-
getUpperBounds
public double[] getUpperBounds()Returns the upper bounds.- Returns:
- the upper bounds.
-
extendLowerBound
public void extendLowerBound(double[] bound) Extends the lower bounds.- Parameters:
bound
- the new lower bounds.
-
extendUpperBound
public void extendUpperBound(double[] bound) Extends the upper bounds.- Parameters:
bound
- the new upper bounds.
-
extendBound
public void extendBound(double[] lowerBound, double[] upperBound) Extends the lower and upper bounds.- Parameters:
lowerBound
- the new lower bounds.upperBound
- the new upper bounds.
-
setBound
public void setBound(double[] lowerBound, double[] upperBound) Sets the lower and upper bounds.- Parameters:
lowerBound
- the new lower bounds.upperBound
- the new upper bounds.
-
paint
Paints the figure.- Parameters:
renderer
- the renderer.
-
show
Shows the plot in a window.- Returns:
- a new JFrame that contains the plot.
- Throws:
InterruptedException
- if we're interrupted while waiting for the event dispatching thread to finish executing.InvocationTargetException
- if an exception is thrown while showing the frame.
-