Class Plot

java.lang.Object
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 a ResultSeries,
  3. box-and-whisker plots of performance statistics (via an IndicatorStatistics), and
  4. other plots of basic data types (e.g., line, scatter, area, stacked, heat map).
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(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 Details

    • Plot

      public Plot()
      Creates a new, empty plot.
  • Method Details

    • setTitle

      public Plot setTitle(String title)
      Sets the chart title.
      Parameters:
      title - the title
      Returns:
      a reference to this 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 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 instance
    • setBackgroundPaint

      public Plot setBackgroundPaint(Paint paint)
      Sets the background paint.
      Parameters:
      paint - the background paint
      Returns:
      a reference to this instance
    • setGridPaint

      public Plot setGridPaint(Paint paint)
      Sets the grid line paint.
      Parameters:
      paint - the grid line paint
      Returns:
      a reference to this 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 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 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 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 instance
    • add

      public Plot add(ResultSeries series)
      Displays the runtime data stored in an ResultSeries as one or more line plots.
      Parameters:
      series - the result series
      Returns:
      a reference to this instance
    • add

      public Plot add(String label, ResultSeries series, String property)
      Displays the runtime data for the given property as a line plot.
      Parameters:
      label - the label for the series
      series - the result series
      property - the name of the property to plot
      Returns:
      a reference to this instance
    • add

      public Plot add(IndicatorStatistics statistics)
      Displays the statistical results from an IndicatorStatistics as a box-and-whisker plot.
      Parameters:
      statistics - the indicator statistics
      Returns:
      a reference to this instance
    • add

      public Plot add(SensitivityResult result)
      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:
      1. First-order effects are rendered as a solid circle / ellipse,
      2. Total-order effects are rendered as a ring around the first-order effects, and
      3. Second-order effects are rendered as lines joining the circles.
      The scale of the circles / lines reflect the relative magnitude of the sensitivities.
      Parameters:
      result - the sensitivity analysis results
      shapeColor - the shape color
      lineColor - the line color
      sensitivityScaling - scaling factor applied to the sensitivity values
      sizeScaling - scaling factor applied to the shape size / thickness
      labelOffset - offsets labels from their shapes
      Returns:
      a reference to this 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 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 instance
    • scatter

      public Plot scatter(String label, Partition<? extends Number,? extends Number> partition)
      Creates a new scatter plot series using the keys and values from a Partition.
      Parameters:
      label - the label for the series
      partition - the data stream partition
      Returns:
      a reference to this 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 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 instance
    • line

      public Plot line(String label, Partition<? extends Number,? extends Number> partition)
      Creates a new line plot series using the keys and values from a Partition.
      Parameters:
      label - the label for the series
      partition - the data stream partition
      Returns:
      a reference to this instance
    • histogram

      public Plot histogram(String label, double[] x, double[] y)
      Creates a new histogram plot series.
      Parameters:
      label - the label for the series
      x - the x values
      y - the y values
      Returns:
      a reference to this instance
    • histogram

      public Plot histogram(String label, List<? extends Number> x, List<? extends Number> y)
      Creates a new histogram plot.
      Parameters:
      label - the label for the series
      x - the x values
      y - the y values
      Returns:
      a reference to this instance
    • histogram

      public Plot histogram(String label, Partition<? extends Number,? extends Number> partition)
      Creates a new histogram plot series using the keys and values from a Partition.
      Parameters:
      label - the label for the series
      partition - the data stream partition
      Returns:
      a reference to this 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 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 instance
    • area

      public Plot area(String label, Partition<? extends Number,? extends Number> partition)
      Creates a new area plot series using the keys and values from a Partition.
      Parameters:
      label - the label for the series
      partition - the data stream partition
      Returns:
      a reference to this 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 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 instance
    • stacked

      public Plot stacked(String label, Partition<? extends Number,? extends Number> partition)
      Creates a new stacked area plot series using the keys and values from a Partition.
      Parameters:
      label - the label for the series
      partition - the data stream partition
      Returns:
      a reference to this instance
    • heatMap

      public Plot heatMap(String label, double[] x, double[] y, double[][] z)
      Creates a new heat map series. The series is added to the given dataset, or if null a new dataset is created.
      Parameters:
      label - the label for the series
      x - the x values
      y - the y values
      z - 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 if null a new dataset is created.
      Parameters:
      label - the label for the series
      x - the x values
      y - the y values
      z - 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 a Partition.
      Parameters:
      label - the label for the series
      partition - the data stream partition
      Returns:
      a reference to this 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 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 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, which must match one of the supported file types in ImageFileType.
      Parameters:
      filename - the filename
      Returns:
      a reference to this 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, which must match one of the supported file types in ImageFileType.
      Parameters:
      file - the file
      Returns:
      a reference to this instance
      Throws:
      IOException - if an I/O error occurred
    • save

      public Plot save(File file, ImageFileType fileType, int width, int height) throws IOException
      Saves the plot to an image file.
      Parameters:
      file - the file
      fileType - the image file format
      width - the image width
      height - 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

      public JFrame show()
      Displays the chart in a standalone window.
      Returns:
      the window that was created
    • 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(Window owner)
      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

      public JDialog showDialog(Window owner, int width, int height)
      Displays the chart in a blocking JDialog.
      Parameters:
      owner - the owner of this dialog, which will be blocked until this dialog is closed
      width - the width of the chart
      height - the height of the chart
      Returns:
      the window that was created