public class SPlot extends Object
Constructor and Description |
---|
SPlot()
Construct a frame with a canvas.
|
SPlot(File f)
Construct a frame with a canvas and open XML file with the data.
|
SPlot(int width,
int height)
Construct a frame with the plot.
|
SPlot(String title,
int width,
int height)
Construct a frame with the plot.
|
Modifier and Type | Method and Description |
---|---|
void |
addLegend(int dataset,
String legend)
Add a legend (displayed at the upper right) for the specified data set
with the specified string.
|
void |
addPoint(int dataset,
double x,
double y,
boolean connected)
In the specified data set, add the specified x, y point to the
plot.
|
void |
addPointErr(int dataset,
double x,
double y,
double yLowEB,
double yHighEB,
boolean connected)
In the specified data set, add the specified x, y point to the
plot with error bars.
|
void |
addXTick(String label,
double position)
Specify a tick mark for the X axis.
|
void |
addYTick(String label,
double position)
Specify a tick mark for the Y axis.
|
void |
clear()
Clear the plot of all data points.
|
void |
clear(int dataset)
Clear the plot of data points in the specified dataset.
|
void |
clearLegends()
Clear all legends.
|
void |
doc()
Show online documentation.
|
void |
draw(double[][] x,
double[][] y)
Draw multiple sets as marks (default).
|
void |
draw(double[] x,
double[] y)
Draw a single data set as marks (default).
|
void |
draw(H1D h1)
Draw H1D histograms
|
void |
draw(P1D p1d)
Draw P1D object.
|
void |
draw(String[] legend,
double[][] x,
double[][] y)
Set sets of data with legends
|
void |
draw(String legend,
double[] x,
double[] y)
Draw a single data set with a legend.
|
void |
draw(String legend,
double[] x,
double[] y,
double[] ey)
Draw a single data set with errors on Y with legend.
|
void |
erasePoint(int dataset,
int index)
Erase the point at the given index in the given dataset.
|
void |
export(String f)
Fast export of the canvas to an image file (depends on the extension,
i.e.
|
void |
fillPlot()
Rescale so that the data that is currently plotted just fits.
|
Color[] |
getColors()
Get the point colors.
|
double[][] |
getData(int index)
Get the data in the specified dataset.
|
boolean |
getGrid()
Return whether the grid is drawn.
|
String |
getLegend(int dataset)
Get the legend for a dataset, or null if there is none.
|
int |
getLegendDataset(String legend)
Given a legend string, return the corresponding dataset or -1 if no
legend was added with that legend string.
|
int |
getNumDataSets()
Return the actual number of data sets.
|
Rectangle |
getPlotRectangle()
Get the current plot rectangle.
|
String |
getTitle()
Get the title of the graph, or an empty string if there is none.
|
double[] |
getXAutoRange()
Get the range for X values of the data points registered so far.
|
String |
getXLabel()
Get the label for the X (horizontal) axis, or null if none has been set.
|
boolean |
getXLog()
Return whether the X axis is drawn with a logarithmic scale.
|
double[] |
getXRange()
Get the X range.
|
Vector[] |
getXTicks()
Get the X ticks that have been specified, or null if none.
|
double[] |
getYAutoRange()
Get the range for Y values of the data points registered so far.
|
String |
getYLabel()
Get the label for the Y (vertical) axis, or null if none has been set.
|
boolean |
getYLog()
Return whether the Y axis is drawn with a logarithmic scale.
|
double[] |
getYRange()
Get the Y range.
|
Vector[] |
getYTicks()
Get the Y ticks that have been specified, or null if none.
|
static void |
main(String[] args) |
void |
read(File file)
Read a XML file and build a plot
|
void |
read(String file)
Read a XML file and build a plot
|
void |
renameLegend(int dataset,
String newName)
Rename a legend.
|
void |
resetAxes()
Reset the X and Y axes to the ranges that were first specified using
setXRange() and setYRange().
|
void |
setAutoRange()
Rescale so that the data that is currently plotted just fits.
|
void |
setAutoRange(boolean auto)
Rescale so that the data that is currently plotted just fits.
|
void |
setBackground(Color c)
Set background for the plot.
|
void |
setBars(boolean on)
Turn bars on or off (for bar charts).
|
void |
setBars(double width,
double offset)
Turn bars on and set the width and offset.
|
void |
setBounds(int x,
int y,
int width,
int height)
Move and resize this component.
|
void |
setColor(boolean useColor)
If the argument is false, draw the plot without using color (in black and
white).
|
void |
setColors(Color[] colors)
Set the point colors.
|
void |
setConnected(boolean on,
int dataset)
If the first argument is true, then by default for the specified dataset,
points will be connected by a line.
|
void |
setEditable(int index)
Specify which dataset is editable.
|
void |
setForeground(Color foreground)
Set the foreground color.
|
void |
setGrid(boolean grid)
Control whether the grid is drawn.
|
void |
setGTitle(String title)
Set global title for this plot.
|
void |
setImpulses(boolean on,
int dataset)
If the first argument is true, then a line will be drawn from any plotted
point in the specified dataset down to the x axis.
|
void |
setLabelFont(String name)
Set the label font, which is used for axis labels and legend labels.
|
void |
setMarksStyle(String style)
Set the marks style to "none", "points", "dots", or "various".
|
void |
setMarksStyle(String style,
int dataset)
Set the marks style to "none", "points", "dots", "various", or "pixels"
for the specified dataset.
|
void |
setNameX(String label)
Set the label for the X (horizontal) axis.
|
void |
setNameY(String label)
Set the label for the Y (vertical) axis.
|
void |
setRange(double xmin,
double xmax,
double ymin,
double ymax)
Set range for X and Y axes.
|
void |
setSize(int width,
int height)
Set size of the frame.
|
void |
setTitle(String title)
Set global title for this plot.
|
void |
setTitleFont(String name)
Set the title font.
|
void |
setWrap(boolean wrap)
Specify whether the X axis is wrapped.
|
void |
setXLog(boolean xlog)
Specify whether the X axis is drawn with a logarithmic scale.
|
void |
setXRange(double min,
double max)
Set the X (horizontal) range of the plot.
|
void |
setYLog(boolean ylog)
Specify whether the Y axis is drawn with a logarithmic scale.
|
void |
setYRange(double min,
double max)
Set the Y (vertical) range of the plot.
|
void |
update()
Repaint the plot and update all graphics.
|
void |
visible()
Show the frame.
|
void |
visible(boolean showIt)
Show or not the frame
|
void |
visible(int posX,
int posY)
Set the canvas frame visible.
|
void |
write(String file)
Write the current plot to a XML file
|
void |
zoom(double lowx,
double lowy,
double highx,
double highy)
Zoom in or out to the specified rectangle.
|
public SPlot()
public SPlot(File f)
f
- file to read.public SPlot(int width, int height)
width
- frame widthheight
- frame heightpublic SPlot(String title, int width, int height)
title
- i Titlewidth
- frame widthheight
- frame heightpublic void setSize(int width, int height)
width
- frame widthheight
- frame heightpublic void setEditable(int index)
index
- index of data setpublic double[][] getData(int index)
index
- index of data setpublic void setBackground(Color c)
c
- background color.public void setGTitle(String title)
title
- plot titlepublic void setTitle(String title)
title
- plot titlepublic void setRange(double xmin, double xmax, double ymin, double ymax)
xmin
- Min for Xxmax
- Max for Xymin
- Min for Yymax
- Max for Ypublic void addLegend(int dataset, String legend)
dataset
- The dataset index.legend
- The label for the dataset.renameLegend(int, String)
public void addXTick(String label, double position)
label
- The label for the tick mark.position
- The position on the X axis.public void addYTick(String label, double position)
label
- The label for the tick mark.position
- The position on the Y axis.public void clear()
public void clearLegends()
public Color[] getColors()
setColors(Color[])
public boolean getGrid()
public String getLegend(int dataset)
dataset
- The dataset index.public int getLegendDataset(String legend)
legend
- The String naming the legendpublic Rectangle getPlotRectangle()
public String getTitle()
public double[] getXAutoRange()
getXRange()
public void setColor(boolean useColor)
useColor
- False to draw in back and white.public void setColors(Color[] colors)
colors
- Array of colors to use in succession for data sets.getColors()
public void setForeground(Color foreground)
foreground
- The foreground color.public void setGrid(boolean grid)
grid
- If true, a grid is drawn.public void setLabelFont(String name)
name
- A font name.public String getXLabel()
public boolean getXLog()
public double[] getXRange()
getXAutoRange()
public Vector[] getXTicks()
public double[] getYAutoRange()
getYRange()
public String getYLabel()
public boolean getYLog()
public double[] getYRange()
setYRange(double, double)
has been called,
then this method returns the values passed in as arguments to
setYRange(double, double). If setYRange(double, double) has not been
called, then this method returns the range of the data to be plotted,
which might not be all of the data due to zooming.getYAutoRange()
public Vector[] getYTicks()
public void renameLegend(int dataset, String newName)
dataset
- The dataset of the legend to be renamed. If there is no
dataset with this value, then nothing happens.newName
- The new name of legend.addLegend(int, String)
public void resetAxes()
public void setBounds(int x, int y, int width, int height)
x
- The new x-coordinate of this component.y
- The new y-coordinate of this component.width
- The new width of this component.height
- The new height of this component.public void setTitleFont(String name)
name
- A font name.public void setWrap(boolean wrap)
wrap
- If true, wrapping of the X axis is enabled.public void setNameX(String label)
label
- The label.public void setXLog(boolean xlog)
xlog
- If true, logarithmic axis is used.public void setXRange(double min, double max)
min
- The left extent of the range.max
- The right extent of the range.public void setNameY(String label)
label
- The label.public void setYLog(boolean ylog)
ylog
- If true, logarithmic axis is used.public void setYRange(double min, double max)
min
- The bottom extent of the range.max
- The top extent of the range.public void zoom(double lowx, double lowy, double highx, double highy)
lowx
- The low end of the new X range.lowy
- The low end of the new Y range.highx
- The high end of the new X range.highy
- The high end of the new Y range.public void write(String file)
file
- File namepublic void read(String file)
file
- File name to readpublic void read(File file)
file
- File name to readpublic void draw(double[][] x, double[][] y)
x
- array of xy
- array of ypublic void draw(double[] x, double[] y)
x
- array of x valuesy
- array of y valuespublic void draw(String legend, double[] x, double[] y)
legend
- legend to showx
- array of x valuesy
- array of y valuespublic void draw(String legend, double[] x, double[] y, double[] ey)
legend
- legend to showx
- array of x valuesy
- array of y valuesey
- array of errors on y valuespublic void clear(int dataset)
In order to work well with swing and be thread safe, this method actually defers execution to the event dispatch thread, where all user interface actions are performed. Thus, the point will not be added immediately (unless you call this method from within the event dispatch thread). If you call this method, the addPoint() method, and the erasePoint() method in any order, they are assured of being processed in the order that you called them.
dataset
- The dataset to clear.public void erasePoint(int dataset, int index)
In order to work well with swing and be thread safe, this method actually defers execution to the event dispatch thread, where all user interface actions are performed. Thus, the point will not be erased immediately (unless you call this method from within the event dispatch thread). All the methods that do this deferring coordinate so that they are executed in the order that you called them.
dataset
- The data set index.index
- The index of the point to erase.public void fillPlot()
In order to work well with swing and be thread safe, this method actually defers execution to the event dispatch thread, where all user interface actions are performed. Thus, the fill will not occur immediately (unless you call this method from within the event dispatch thread). All the methods that do this deferring coordinate so that they are executed in the order that you called them.
public void setAutoRange()
public void setAutoRange(boolean auto)
auto
- if true, then autorangepublic void update()
public int getNumDataSets()
public void setBars(boolean on)
on
- If true, turn bars on.public void setBars(double width, double offset)
width
- The width of the bars.offset
- The offset per data set.public void setConnected(boolean on, int dataset)
on
- If true, draw lines between points.dataset
- The dataset to which this should apply.public void addPoint(int dataset, double x, double y, boolean connected)
In order to work well with swing and be thread safe, this method actually defers execution to the event dispatch thread, where all user interface actions are performed. Thus, the point will not be added immediately (unless you call this method from within the event dispatch thread). All the methods that do this deferring coordinate so that they are executed in the order that you called them.
dataset
- The data set index.x
- The X position of the new point.y
- The Y position of the new point.connected
- If true, a line is drawn to connect to the previous
point.public void addPointErr(int dataset, double x, double y, double yLowEB, double yHighEB, boolean connected)
In order to work well with swing and be thread safe, this method actually defers execution to the event dispatch thread, where all user interface actions are performed. Thus, the point will not be added immediately (unless you call this method from within the event dispatch thread). All the methods that do this deferring coordinate so that they are executed in the order that you called them.
dataset
- The data set index.x
- The X position of the new point.y
- The Y position of the new point.yLowEB
- The low point of the error bar.yHighEB
- The high point of the error bar.connected
- If true, a line is drawn to connect to the previous
point.public void setImpulses(boolean on, int dataset)
on
- If true, draw a stem plot.dataset
- The dataset to which this should apply.public void setMarksStyle(String style)
style
- A string specifying the style for points.public void setMarksStyle(String style, int dataset)
style
- A string specifying the style for points.dataset
- The dataset to which this should apply.public void draw(H1D h1)
h1
- H1D histogram to be shown.public void draw(P1D p1d)
p1d
- P1D object to showpublic void draw(String[] legend, double[][] x, double[][] y)
legend
- array of legendsx
- array of xy
- array of ypublic void visible(boolean showIt)
showIt
- true if should be shownpublic void visible()
public void visible(int posX, int posY)
posX
- - the x-coordinate of the new location's top-left corner in the parent's coordinate space;posY
- - he y-coordinate of the new location's top-left corner in the parent's coordinate spacepublic static void main(String[] args)
public void export(String f)
f
- Output file with the proper extension. If no extension, PNG
file is assumed.public void doc()
SCaVis 1.0 ©