Class Plot
- scatter plots of bi-objective populations,
- line plots of runtime dynamics (via a
ResultSeries
, - box-and-whisker plots of performance statistics (via an
IndicatorStatistics
), 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.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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd
(String label, ResultSeries series, String property) Displays the runtime data for the given property 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
(IndicatorStatistics statistics) Displays the statistical results from anIndicatorStatistics
as a box-and-whisker plot.add
(SensitivityResult result) Displays sensitivity analysis results in a "spider web" plot.add
(SensitivityResult result, Color shapeColor, Color lineColor, double sensitivityScaling, double sizeScaling, double labelOffset) Displays sensitivity analysis results in a "spider web" plot, where: First-order effects are rendered as a solid circle / ellipse, Total-order effects are rendered as a ring around the first-order effects, and Second-order effects are rendered as lines joining the circles.add
(ResultSeries series) Displays the runtime data stored in anResultSeries
as one or more line plots.Creates a new area plot series.Creates a new area plot series.Creates a new area plot series using the keys and values from aPartition
.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.heatMap
(String label, Partition<? extends org.apache.commons.lang3.tuple.Pair<? extends Number, ? extends Number>, ? extends Number> partition) Creates a new heat map series using the keys and values from aPartition
.Creates a new histogram plot series.Creates a new histogram plot.Creates a new histogram plot series using the keys and values from aPartition
.Creates a new line plot series.Creates a new line plot series.Creates a new line plot series using the keys and values from aPartition
.Saves the plot to an image file.save
(File file, ImageFileType 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.Creates a new scatter plot series using the keys and values from aPartition
.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.showDialog
(Window owner) Displays the chart in a blocking JDialog.showDialog
(Window owner, 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.Creates a new stacked area plot series using the keys and values from aPartition
.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 instance
-
setXLabel
Sets the x-axis label.- Parameters:
label
- the label for the x-axis- Returns:
- a reference to this instance
-
setYLabel
Sets the y-axis label.- Parameters:
label
- the label for the y-axis- Returns:
- a reference to this instance
-
setBackgroundPaint
Sets the background paint.- Parameters:
paint
- the background paint- Returns:
- a reference to this instance
-
setGridPaint
Sets the grid line paint.- Parameters:
paint
- the grid line paint- Returns:
- a reference to this 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 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 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 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 instance
-
add
Displays the runtime data stored in anResultSeries
as one or more line plots.- Parameters:
series
- the result series- Returns:
- a reference to this instance
-
add
Displays the runtime data for the given property as a line plot.- Parameters:
label
- the label for the seriesseries
- the result seriesproperty
- the name of the property to plot- Returns:
- a reference to this instance
-
add
Displays the statistical results from anIndicatorStatistics
as a box-and-whisker plot.- Parameters:
statistics
- the indicator statistics- Returns:
- a reference to this instance
-
add
Displays sensitivity analysis results in a "spider web" plot.- Parameters:
result
- the sensitivity analysis results- Returns:
- a reference to this instance
-
add
public Plot add(SensitivityResult result, Color shapeColor, Color lineColor, double sensitivityScaling, double sizeScaling, double labelOffset) Displays sensitivity analysis results in a "spider web" plot, where:- First-order effects are rendered as a solid circle / ellipse,
- Total-order effects are rendered as a ring around the first-order effects, and
- Second-order effects are rendered as lines joining the circles.
- Parameters:
result
- the sensitivity analysis resultsshapeColor
- the shape colorlineColor
- the line colorsensitivityScaling
- scaling factor applied to the sensitivity valuessizeScaling
- scaling factor applied to the shape size / thicknesslabelOffset
- offsets labels from their shapes- Returns:
- a reference to this 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 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 instance
-
scatter
Creates a new scatter plot series using the keys and values from aPartition
.- Parameters:
label
- the label for the seriespartition
- the data stream partition- Returns:
- a reference to this 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 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 instance
-
line
Creates a new line plot series using the keys and values from aPartition
.- Parameters:
label
- the label for the seriespartition
- the data stream partition- Returns:
- a reference to this instance
-
histogram
Creates a new histogram plot series.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y values- Returns:
- a reference to this instance
-
histogram
Creates a new histogram plot.- Parameters:
label
- the label for the seriesx
- the x valuesy
- the y values- Returns:
- a reference to this instance
-
histogram
Creates a new histogram plot series using the keys and values from aPartition
.- Parameters:
label
- the label for the seriespartition
- the data stream partition- Returns:
- a reference to this 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 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 instance
-
area
Creates a new area plot series using the keys and values from aPartition
.- Parameters:
label
- the label for the seriespartition
- the data stream partition- Returns:
- a reference to this 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 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 instance
-
stacked
Creates a new stacked area plot series using the keys and values from aPartition
.- Parameters:
label
- the label for the seriespartition
- the data stream partition- Returns:
- a reference to this 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 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 instance
-
heatMap
public Plot heatMap(String label, Partition<? extends org.apache.commons.lang3.tuple.Pair<? extends Number, ? extends Number>, ? extends Number> partition) Creates a new heat map series using the keys and values from aPartition
.- Parameters:
label
- the label for the seriespartition
- the data stream partition- Returns:
- a reference to this 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 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 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 inImageFileType
.- Parameters:
filename
- the filename- Returns:
- a reference to this 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 inImageFileType
.- Parameters:
file
- the file- Returns:
- a reference to this 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 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
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.- Parameters:
owner
- the owner of this dialog, which will be blocked until this dialog is closed- Returns:
- the window that was created
-
showDialog
Displays the chart in a blocking JDialog.- Parameters:
owner
- the owner of this dialog, which will be blocked until this dialog is closedwidth
- the width of the chartheight
- the height of the chart- Returns:
- the window that was created
-