Class Plot
- scatter plots of bi-objective populations,
- line plots of runtime dynamics (via an
Observations
, - box-and-whisker plots of performance statistics (via an
Analyzer
), and - other plots of basic data types (e.g., line, scatter, area, stacked, heat map).
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(java.lang.String, double[], double[])
, scatter(java.lang.String, double[], double[])
, area(java.lang.String, double[], double[])
,
stacked(java.lang.String, double[], double[])
, heatMap(java.lang.String, double[], double[], double[][])
or any of the add(java.lang.String, org.moeaframework.core.Population)
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(java.lang.String)
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 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/.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
List of supported file types when saving a plot. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(String label, Observations observations, String metric) Displays the runtime data for the given metric as a line plot.add
(String label, Population population) Displays the solutions in the given population in a 2D scatter plot.add
(String label, Population population, int x, int y) Displays the solutions in the given population in a 2D scatter plot.add
(Observations observations) Displays the runtime data stored in anObservations
as one or more line plots.Displays the statistical results from anAnalyzer
as a box-and-whisker plot.add
(Analyzer.AnalyzerResults result) Displays the statistical results from anAnalyzer.AnalyzerResults
as a box-and-whisker plot.Creates a new area plot series.Creates a new area plot series.org.jfree.chart.JFreeChart
getChart()
Returns the internal chart.org.jfree.chart.ChartPanel
Returns the chart embedded in a Swing panel for display.Creates a new heat map series.heatMap
(String label, List<? extends Number> x, List<? extends Number> y, List<? extends List<? extends Number>> z) Creates a new heat map series.Creates a new line plot series.Creates a new line plot series.Saves the plot to an image file.Saves the plot to an image file.save
(File file, Plot.FileType fileType, int width, int height) Saves the plot to an image file.Saves the plot to an image file.Creates a new scatter plot series.Creates a new scatter plot series.setBackgroundPaint
(Paint paint) Sets the background paint.setGridPaint
(Paint paint) Sets the grid line paint.Sets the chart title.Sets the x-axis label.setXLim
(double min, double max) Sets the x-axis limits.Sets the y-axis label.setYLim
(double min, double max) Sets the y-axis limits.show()
Displays the chart in a standalone window.show
(int width, int height) Displays the chart in a standalone window.Displays the chart in a blocking JDialog.showDialog
(int width, int height) Displays the chart in a blocking JDialog.Creates a new stacked area plot series.Creates a new stacked area plot series.static boolean
Returnstrue
if saving to the SVG format is supported.Modifies the paint (e.g,.withSize
(float size) Modifies the line thickness or point size in the last dataset.
-
Constructor Details
-
Plot
public Plot()Creates a new, empty plot.
-
-
Method Details
-
setTitle
Sets the chart title.- Parameters:
title
- the title- Returns:
- a reference to this
Plot
instance
-
setXLabel
Sets the x-axis label.- Parameters:
label
- the label for the x-axis- Returns:
- a reference to this
Plot
instance
-
setYLabel
Sets the y-axis label.- Parameters:
label
- the label for the y-axis- Returns:
- a reference to this
Plot
instance
-
setBackgroundPaint
Sets the background paint.- Parameters:
paint
- the background paint- Returns:
- a reference to this
Plot
instance
-
setGridPaint
Sets the grid line paint.- Parameters:
paint
- the grid line paint- Returns:
- a reference to this
Plot
instance
-
setXLim
Sets the x-axis limits.- Parameters:
min
- the minimum bound for the x-axismax
- the maximum bound for the x-axis- Returns:
- a reference to this
Plot
instance
-
setYLim
Sets the y-axis limits.- Parameters:
min
- the minimum bound for the y-axismax
- the maximum bound for the y-axis- Returns:
- a reference to this
Plot
instance
-
scatter
Creates a new scatter plot series.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y values- Returns:
- a reference to this
Plot
instance
-
scatter
Creates a new scatter plot series.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y values- Returns:
- a reference to this
Plot
instance
-
add
Displays the solutions in the given population in a 2D scatter plot. Only two objectives will be displayed.- Parameters:
label
- the label for the seriespopulation
- the population- Returns:
- a reference to this
Plot
instance
-
add
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 seriespopulation
- the populationx
- the objective to plot on the x-axisy
- the objective to plot on the y-axis- Returns:
- a reference to this
Plot
instance
-
add
Displays the runtime data stored in anObservations
as one or more line plots.- Parameters:
observations
- theObservations
instance- Returns:
- a reference to this
Plot
instance
-
add
Displays the runtime data for the given metric as a line plot.- Parameters:
label
- the label for the seriesobservations
- theObservations
instancemetric
- the name of the performance metric to plot- Returns:
- a reference to this
Plot
instance
-
line
Creates a new line plot series.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y values- Returns:
- a reference to this
Plot
instance
-
line
Creates a new line plot series.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y values- Returns:
- a reference to this
Plot
instance
-
area
Creates a new area plot series.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y values- Returns:
- a reference to this
Plot
instance
-
area
Creates a new area plot series.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y values- Returns:
- a reference to this
Plot
instance
-
stacked
Creates a new stacked area plot series. The data will be stacked with any preceding calls tostacked
.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y values- Returns:
- a reference to this
Plot
instance
-
stacked
Creates a new stacked area plot series. The data will be stacked with any preceding calls tostacked
.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y values- Returns:
- a reference to this
Plot
instance
-
heatMap
Creates a new heat map series. The series is added to the given dataset, or ifnull
a new dataset is created.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y valuesz
- the z values- Returns:
- a reference to this
Plot
instance
-
heatMap
public Plot heatMap(String label, List<? extends Number> x, List<? extends Number> y, List<? extends List<? extends Number>> z) Creates a new heat map series. The series is added to the given dataset, or ifnull
a new dataset is created.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y valuesz
- the z values- Returns:
- a reference to this
Plot
instance
-
add
Displays the statistical results from anAnalyzer
as a box-and-whisker plot.- Parameters:
analyzer
- theAnalyzer
instance- Returns:
- a reference to this
Plot
instance
-
add
Displays the statistical results from anAnalyzer.AnalyzerResults
as a box-and-whisker plot.- Parameters:
result
- theAnalyzerResults
instance- Returns:
- a reference to this
Plot
instance
-
withSize
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
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
Saves the plot to an image file. The type of image is determined from the filename extension, which must match one of the supported file types inPlot.FileType
.- Parameters:
filename
- the filename- Returns:
- a reference to this
Plot
instance - Throws:
IOException
- if an I/O error occurred
-
save
Saves the plot to an image file. The type of image is determined from the filename extension, which must match one of the supported file types inPlot.FileType
.- Parameters:
file
- the file- Returns:
- a reference to this
Plot
instance - Throws:
IOException
- if an I/O error occurred
-
save
Saves the plot to an image file. The format must match one of the supported file types inPlot.FileType
.- Parameters:
file
- the fileformat
- the image formatwidth
- the image widthheight
- the image height- Returns:
- a reference to this
Plot
instance - Throws:
IOException
- if an I/O error occurred
-
save
Saves the plot to an image file.- Parameters:
file
- the filefileType
- the image file formatwidth
- the image widthheight
- the image height- Returns:
- a reference to this
Plot
instance - Throws:
IOException
- if an I/O error occurred
-
supportsSVG
public static boolean supportsSVG()Returnstrue
if saving to the SVG format is supported. This requires the JFreeSVG library to be setup on the classpath.- Returns:
true
if saving to the SVG format is supported;false
otherwise
-
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
Displays the chart in a standalone window.- Returns:
- the window that was created
-
show
Displays the chart in a standalone window.- Parameters:
width
- the width of the chartheight
- the height of the chart- Returns:
- the window that was created
-
showDialog
Displays the chart in a blocking JDialog.- Returns:
- the window that was created
-
showDialog
Displays the chart in a blocking JDialog.- Parameters:
width
- the width of the chartheight
- the height of the chart- Returns:
- the window that was created
-