MOEA Framework 2.12
API Specification

org.moeaframework.analysis.plot
Class Plot

java.lang.Object
  extended by org.moeaframework.analysis.plot.Plot

public class Plot
extends Object

Provides simple 2D plotting capabilities. This is intended to allow the rapid creation of 2D plots, supporting:

  1. scatter plots of bi-objective populations,
  2. line plots of runtime dynamics (via an Accumulator,
  3. box-and-whisker plots of performance statistics (via an Analyzer), and
  4. other plots of basic data types (e.g., line, scatter, area, stacked).
It is possible to combine datasets by calling more than one add method, but you can not mix different plot types (e.g., XY plots versus categorical plots). Thus, box-and-whisker plots can not be overlaid on a line plot.

In general, one should first generate the plot artifacts by calling line, scatter, area, stacked, or any of the add methods. Artifacts can be customized by immediately calling one of the with* methods after generating the artifact (the customization is only applied to the last artifact). Lastly, call the set* methods to customize the overall appearance of the chart. Call show to display the chart in a window or save to create an image file. For example:

       new Plot()
                .scatter("Point", new double[] { 0.0, 1.0, 2.0 }, new double[] { 3.0, 4.0, 5.0 })
                        .withPaint(Color.BLACK)
                .line("Line", new double[] { 0.0, 2.0 }, new double[] { 3.0, 5.0 })
                        .withSize(5)
                .setXLabel("X")
                .setYLabel("Y")
                .setTitle("Example")
                .show();
 

This class is not intended to be a fully featured plotting library. To generate more sophisticated plots or customize their appearance, one must instead use JFreeChart, JZY3D, or another Java plotting library.

Generated plots can be saved to PNG or JPEG files. If JFreeSVG is available on the classpath, SVG files can be generated. JFreeSVG can be obtained from http://www.jfree.org/jfreesvg/.


Constructor Summary
Plot()
          Creates a new, empty plot.
 
Method Summary
 Plot add(Accumulator accumulator)
          Displays the runtime data stored in an Accumulator as one or more line plots.
 Plot add(Analyzer.AnalyzerResults result)
          Displays the statistical results from an Analyzer.AnalyzerResults as a box-and-whisker plot.
 Plot add(Analyzer analyzer)
          Displays the statistical results from an Analyzer as a box-and-whisker plot.
 Plot add(String label, Accumulator accumulator, String metric)
          Displays the runtime data for the given metric as a line plot.
 Plot add(String label, Population population)
          Displays the solutions in the given population in a 2D scatter plot.
 Plot add(String label, Population population, int x, int y)
          Displays the solutions in the given population in a 2D scatter plot.
 Plot area(String label, double[] x, double[] y)
          Creates a new area plot series.
 Plot area(String label, List<? extends Number> x, List<? extends Number> y)
          Creates a new area plot series.
 org.jfree.chart.JFreeChart getChart()
          Returns the internal chart.
 org.jfree.chart.ChartPanel getChartPanel()
          Returns the chart embedded in a Swing panel for display.
 Plot line(String label, double[] x, double[] y)
          Creates a new line plot series.
 Plot line(String label, List<? extends Number> x, List<? extends Number> y)
          Creates a new line plot series.
 Plot save(File file)
          Saves the plot to an image file.
 Plot save(File file, String format, int width, int height)
          Saves the plot to an image file.
 Plot save(String filename)
          Saves the plot to an image file.
 Plot scatter(String label, double[] x, double[] y)
          Creates a new scatter plot series.
 Plot scatter(String label, List<? extends Number> x, List<? extends Number> y)
          Creates a new scatter plot series.
 Plot setBackgroundPaint(Paint paint)
          Sets the background paint.
 Plot setGridPaint(Paint paint)
          Sets the grid line paint.
 Plot setTitle(String title)
          Sets the chart title.
 Plot setXLabel(String label)
          Sets the x-axis label.
 Plot setXLim(double min, double max)
          Sets the x-axis limits.
 Plot setYLabel(String label)
          Sets the y-axis label.
 Plot setYLim(double min, double max)
          Sets the y-axis limits.
 JFrame show()
          Displays the chart in a standalone window.
 JFrame show(int width, int height)
          Displays the chart in a standalone window.
 JDialog showDialog()
          Displays the chart in a blocking JDialog.
 JDialog showDialog(int width, int height)
          Displays the chart in a blocking JDialog.
 Plot stacked(String label, double[] x, double[] y)
          Creates a new stacked area plot series.
 Plot stacked(String label, List<? extends Number> x, List<? extends Number> y)
          Creates a new stacked area plot series.
 Plot withPaint(Paint... paint)
          Modifies the paint (e.g,.
 Plot withSize(float size)
          Modifies the line thickness or point size in the last dataset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Plot

public Plot()
Creates a new, empty plot.

Method Detail

setTitle

public Plot setTitle(String title)
Sets the chart title.

Parameters:
title - the title
Returns:
a reference to this Plot instance

setXLabel

public Plot setXLabel(String label)
Sets the x-axis label.

Parameters:
label - the label for the x-axis
Returns:
a reference to this Plot instance

setYLabel

public Plot setYLabel(String label)
Sets the y-axis label.

Parameters:
label - the label for the y-axis
Returns:
a reference to this Plot instance

setBackgroundPaint

public Plot setBackgroundPaint(Paint paint)
Sets the background paint.

Parameters:
paint - the background paint
Returns:
a reference to this Plot instance

setGridPaint

public Plot setGridPaint(Paint paint)
Sets the grid line paint.

Parameters:
paint - the grid line paint
Returns:
a reference to this Plot instance

setXLim

public Plot setXLim(double min,
                    double max)
Sets the x-axis limits.

Parameters:
min - the minimum bound for the x-axis
max - the maximum bound for the x-axis
Returns:
a reference to this Plot instance

setYLim

public Plot setYLim(double min,
                    double max)
Sets the y-axis limits.

Parameters:
min - the minimum bound for the y-axis
max - the maximum bound for the y-axis
Returns:
a reference to this Plot instance

scatter

public Plot scatter(String label,
                    double[] x,
                    double[] y)
Creates a new scatter plot series.

Parameters:
label - the label for the series
x - the x values
y - the y values
Returns:
a reference to this Plot instance

scatter

public Plot scatter(String label,
                    List<? extends Number> x,
                    List<? extends Number> y)
Creates a new scatter plot series.

Parameters:
label - the label for the series
x - the x values
y - the y values
Returns:
a reference to this Plot instance

add

public Plot add(String label,
                Population population)
Displays the solutions in the given population in a 2D scatter plot. Only two objectives will be displayed.

Parameters:
label - the label for the series
population - the population
Returns:
a reference to this Plot instance

add

public Plot add(String label,
                Population population,
                int x,
                int y)
Displays the solutions in the given population in a 2D scatter plot. The two given objectives will be displayed.

Parameters:
label - the label for the series
population - the population
x - the objective to plot on the x-axis
y - the objective to plot on the y-axis
Returns:
a reference to this Plot instance

add

public Plot add(Accumulator accumulator)
Displays the runtime data stored in an Accumulator as one or more line plots.

Parameters:
accumulator - the Accumulator instance
Returns:
a reference to this Plot instance

add

public Plot add(String label,
                Accumulator accumulator,
                String metric)
Displays the runtime data for the given metric as a line plot.

Parameters:
label - the label for the series
accumulator - the Accumulator instance
metric - the name of the performance metric to plot
Returns:
a reference to this Plot instance

line

public Plot line(String label,
                 double[] x,
                 double[] y)
Creates a new line plot series.

Parameters:
label - the label for the series
x - the x values
y - the y values
Returns:
a reference to this Plot instance

line

public Plot line(String label,
                 List<? extends Number> x,
                 List<? extends Number> y)
Creates a new line plot series.

Parameters:
label - the label for the series
x - the x values
y - the y values
Returns:
a reference to this Plot instance

area

public Plot area(String label,
                 double[] x,
                 double[] y)
Creates a new area plot series.

Parameters:
label - the label for the series
x - the x values
y - the y values
Returns:
a reference to this Plot instance

area

public Plot area(String label,
                 List<? extends Number> x,
                 List<? extends Number> y)
Creates a new area plot series.

Parameters:
label - the label for the series
x - the x values
y - the y values
Returns:
a reference to this Plot instance

stacked

public Plot stacked(String label,
                    double[] x,
                    double[] y)
Creates a new stacked area plot series. The data will be stacked with any preceding calls to stacked.

Parameters:
label - the label for the series
x - the x values
y - the y values
Returns:
a reference to this Plot instance

stacked

public Plot stacked(String label,
                    List<? extends Number> x,
                    List<? extends Number> y)
Creates a new stacked area plot series. The data will be stacked with any preceding calls to stacked.

Parameters:
label - the label for the series
x - the x values
y - the y values
Returns:
a reference to this Plot instance

add

public Plot add(Analyzer analyzer)
Displays the statistical results from an Analyzer as a box-and-whisker plot.

Parameters:
analyzer - the Analyzer instance
Returns:
a reference to this Plot instance

add

public Plot add(Analyzer.AnalyzerResults result)
Displays the statistical results from an Analyzer.AnalyzerResults as a box-and-whisker plot.

Parameters:
result - the AnalyzerResults instance
Returns:
a reference to this Plot instance

withSize

public Plot withSize(float size)
Modifies the line thickness or point size in the last dataset. The size is applied to all series in the dataset.

Parameters:
size - the size
Returns:
a reference to this Plot instance

withPaint

public Plot withPaint(Paint... paint)
Modifies the paint (e.g,. color) of each series in the last dataset. If the dataset contains more series than the number of arguments, the arguments are reused as needed.

Parameters:
paint - one or more paint instances
Returns:
a reference to this Plot instance

save

public Plot save(String filename)
          throws IOException
Saves the plot to an image file. The type of image is determined from the filename extension. See save(File, String, int, int) for a list of supported types.

Parameters:
filename - the filename
Returns:
a reference to this Plot instance
Throws:
IOException - if an I/O error occurred

save

public Plot save(File file)
          throws IOException
Saves the plot to an image file. The type of image is determined from the filename extension. See save(File, String, int, int) for a list of supported types.

Parameters:
file - the file
Returns:
a reference to this Plot instance
Throws:
IOException - if an I/O error occurred

save

public Plot save(File file,
                 String format,
                 int width,
                 int height)
          throws IOException
Saves the plot to an image file. The format must be one of png, jpeg, or svg (requires JFreeSVG).

Parameters:
file - the file
format - the image format
width - the image width
height - the image height
Returns:
a reference to this Plot instance
Throws:
IOException - if an I/O error occurred

getChart

public org.jfree.chart.JFreeChart getChart()
Returns the internal chart. Allows further modification of the appearance of the chart.

Returns:
the internal JFreeChart instance

getChartPanel

public org.jfree.chart.ChartPanel getChartPanel()
Returns the chart embedded in a Swing panel for display.

Returns:
a Swing panel for displaying the chart

show

public JFrame show()
Displays the chart in a standalone window.


show

public JFrame show(int width,
                   int height)
Displays the chart in a standalone window.

Parameters:
width - the width of the chart
height - the height of the chart
Returns:
the window that was created

showDialog

public JDialog showDialog()
Displays the chart in a blocking JDialog.


showDialog

public JDialog showDialog(int width,
                          int height)
Displays the chart in a blocking JDialog.

Parameters:
width - the width of the chart
height - the height of the chart
Returns:
the window that was created

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!