Class Plot3D

java.lang.Object
com.eco.bio7.spatial.Plot3D

public class Plot3D extends Object
A simple API to create 3D plots in the 3D view (the space view) without OpenGL code: the data of one or more plot layers (scatter, line, filled line, surface, wireframe, bars, contour, pie and the charts line graph, box plot, violin plot, histogram, area, radar, rose and treemap, see PlotCharts) with a title, axis titles, log axes, number formats, a legend and a color bar. The data is fitted into the plot box (the axis numbers show the values of the data) and the plot is drawn in the 3D view (also without a running model). A plot can be exported to an HTML page with WebGL (see exportHtml).

Example (Java or Groovy):

double[] x = ..., y = ..., z = ...;
new Plot3D().title("Measurements").axisTitles("Length [cm]", "Width [cm]", "Height [cm]")
                .add(Plot3D.scatter(x, y, z).label("Species A"))
                .show();

new Plot3D().title("z = sin(x) cos(y)").add(Plot3D.surface(xs, ys, zGrid).colorMap(PlotLegend.VIRIDIS))
                .colorBarTitle("z").show();

Plot3D.clear(); // removes the plot
The texts can contain the math markup of the plot view (x^2, x^{-0.5}, N_0).
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Bars (boxes) from the floor (or 0) to the values.
    static final class 
    The contour lines of a grid (at their heights or on the floor).
    static final class 
    A line filled down to the floor (a ribbon).
    static class 
    A layer of a plot with the common settings: a label (for the legend), a color, a color map and the transparency.
    static class 
    A line through the points.
    static final class 
    A 3D pie chart (without axes, the labels in the legend and the percentages at the slices).
    static final class 
    A scatter plot: spheres at the points.
    static final class 
    A surface of a grid (smooth shading, optional with the lines of the grid).
    static final class 
    A wireframe of a grid.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int[]
    The colors of the layers without a color (like the categories of R or matplotlib).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Plot3D.Layer<?> layer)
    Adds a layer (e.g., Plot3D.scatter(x, y, z)).
    static com.eco.bio7.spatial.PlotCharts.Area
    area(double[] x, double[][] series)
    An area chart of series over x (stacked, see PlotCharts.Area).
    aspect(double x, double y, double z)
    The proportions of the plot box (default 1, 1, 0.75), e.g., 1, 1, 1 for a cube or 2, 1, 1 for a long x axis.
    static String[]
    Returns the names of the font families which are installed (for font and fonts).
    The titles of the axes (null = X, Y, Z).
    bars(double[] x, double[] y, double[] z)
    Bars at the points (x[i], y[i]) with the heights z[i].
    bars(double[] x, double[] y, double[][] z)
    Bars of the grid z[i][j] at x[i], y[j] (e.g., a 2D histogram).
    static com.eco.bio7.spatial.PlotCharts.BoxPlot
    boxplot(double[][] groups, String[] names)
    A box plot of groups (the values of each group, the names on the x axis, see PlotCharts.BoxPlot).
    categories(int axis, String... labels)
    The categories of an axis (e.g., the names of groups): the numbers of the axis are the names at the positions 0, 1, 2, ...
    static void
    Removes the displayed plot from the 3D view (and the title, the axes and the legends of the plot).
    Removes all layers (e.g., to add the layers of the next step of a simulation, see update).
    The title of the color bar (default: the title of the z axis).
    contour(double[] x, double[] y, double[][] z)
    The contour lines of the grid z[i][j] at x[i], y[j].
    exportAction(boolean visible)
    Shows the action "Export Plot (WebGL, Blender)" in the toolbar of the 3D view when the plot is displayed (see setExportAction).
    Exports the plot for Blender: the glTF file (see exportGltf) and a Python script with the same name (*.py) which imports the file in Blender and adds the title, the axis titles and the numbers as text objects, a camera and the lights (in Blender: Scripting - Open - Run Script).
    void
    Exports the plot to a glTF binary file (*.glb), e.g., for Blender (File - Import - glTF 2.0): an object for each layer (named after the label) with the vertex colors, the points as spheres, the lines as tubes and the box, the grids and the axes as an object "Frame" (not for a pie chart).
    void
    Exports the plot to an HTML page with WebGL (a single file without dependencies): the plot can be rotated with the mouse and zoomed with the mouse wheel in a web browser.
    filledLine(double[] x, double[] y, double[] z)
    A line through the points filled down to the floor (e.g., several series at different y).
    font(String family)
    The font family of all texts (e.g., "Arial", null = Verdana, see fonts).
    fonts(String title, String numbers, String axisTitles, String legend)
    The font families of the texts (e.g., "Arial", "Georgia", null = Verdana): the title, the numbers of the axes (and the labels of the data), the titles of the axes and the legend with the color bar.
    static Plot3D
    Returns the displayed plot or null.
    grids(boolean xy, boolean xz, boolean yz)
    The grids behind the data: the floor (XY) and the walls (XZ, YZ).
    static com.eco.bio7.spatial.PlotCharts.Histogram
    histogram(double[] values)
    A histogram of values (see PlotCharts.Histogram).
    static com.eco.bio7.spatial.PlotCharts.Histogram
    histogram(double[][] groups, String[] names)
    Histograms of groups (in the depth with the names on the y axis, see PlotCharts.Histogram).
    int
    Returns the number of the layers.
    legend(boolean legend)
    Displays the legend of the layers with a label (default true).
    line(double[] x, double[] y, double[] z)
    A line through the points (x[i], y[i], z[i]).
    static com.eco.bio7.spatial.PlotCharts.LineGraph
    lineGraph(double[] x, double[][] series)
    A line graph: the series of values over x (series[k][i] at x[i]), each series a line with markers at its own position in the depth (see PlotCharts.LineGraph).
    logAxes(boolean x, boolean y, boolean z)
    Logarithmic axes: the data of the axes are displayed logarithmic (values invalid input: '<'= 0 are not displayed).
    The formats of the axis numbers (java.util.Formatter, e.g., "%.1f", "10^" for powers of ten, null = automatic).
    static Plot3D.Pie
    pie(double[] values, String[] labels)
    A 3D pie chart of the values (the labels are displayed in the legend).
    static com.eco.bio7.spatial.PlotCharts.Radar
    radar(double[][] series, String[] axes)
    A radar chart: the values of the series (series[k][axis]) on the axes (without the axes of the box, see PlotCharts.Radar).
    remove(int index)
    Removes a layer (the index of add).
    static com.eco.bio7.spatial.PlotCharts.Rose
    rose(double[][] values, String[] sectors)
    A rose chart with classes: values[sector][class] stacked from the center (e.g., the wind speeds of a wind rose).
    static com.eco.bio7.spatial.PlotCharts.Rose
    rose(double[] values, String[] sectors)
    A rose chart: a value for each sector (e.g., the directions of a wind rose, see PlotCharts.Rose).
    scatter(double[] x, double[] y, double[] z)
    A scatter plot (spheres) of the points (x[i], y[i], z[i]).
    set(int index, Plot3D.Layer<?> layer)
    Replaces a layer (the index of add).
    static void
    setExportAction(boolean visible)
    Shows or hides the action "Export Plot (WebGL, Blender)" in the toolbar of the 3D view (hidden by default).
    Displays the plot in the 3D view (opens the 3D perspective if necessary).
    surface(double[] x, double[] y, double[][] z)
    A surface of the grid z[i][j] at x[i], y[j].
    textColor(int rgb)
    The color of all texts (0xRRGGBB, -1 = the color of the lines of the 3D view).
    textColors(int title, int numbers, int axisTitles, int legend)
    The colors of the texts (0xRRGGBB, -1 = the color of the lines of the 3D view): the title, the numbers of the axes (and the labels of the data, e.g., the percentages of a pie chart), the titles of the axes and the legend with the color bar.
    title(String title)
    The title of the plot (lines separated with \n).
    static com.eco.bio7.spatial.PlotCharts.Treemap
    treemap(double[] values, String[] labels)
    A treemap of the values (rectangles with the area of the values, see PlotCharts.Treemap).
    Updates the displayed plot with the current layers (e.g., in each step of a simulation, also from the OpenGL thread of a model): the plot is computed again and the 3D view displays it in the next frame.
    static com.eco.bio7.spatial.PlotCharts.Violin
    violin(double[][] groups, String[] names)
    A violin plot of groups (the kernel density of the values of each group, see PlotCharts.Violin).
    wireframe(double[] x, double[] y, double[][] z)
    A wireframe of the grid z[i][j] at x[i], y[j].
    xRange(double min, double max)
    The range of the x axis (instead of the range of the data).
    yRange(double min, double max)
    The range of the y axis (instead of the range of the data).
    zRange(double min, double max)
    The range of the z axis (instead of the range of the data).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CATEGORY_COLORS

      public static final int[] CATEGORY_COLORS
      The colors of the layers without a color (like the categories of R or matplotlib).
  • Constructor Details

    • Plot3D

      public Plot3D()
  • Method Details

    • title

      public Plot3D title(String title)
      The title of the plot (lines separated with \n).
    • axisTitles

      public Plot3D axisTitles(String x, String y, String z)
      The titles of the axes (null = X, Y, Z).
    • logAxes

      public Plot3D logAxes(boolean x, boolean y, boolean z)
      Logarithmic axes: the data of the axes are displayed logarithmic (values invalid input: '<'= 0 are not displayed). The data is given in the original values.
    • numberFormats

      public Plot3D numberFormats(String x, String y, String z)
      The formats of the axis numbers (java.util.Formatter, e.g., "%.1f", "10^" for powers of ten, null = automatic).
    • xRange

      public Plot3D xRange(double min, double max)
      The range of the x axis (instead of the range of the data).
    • yRange

      public Plot3D yRange(double min, double max)
      The range of the y axis (instead of the range of the data).
    • zRange

      public Plot3D zRange(double min, double max)
      The range of the z axis (instead of the range of the data).
    • aspect

      public Plot3D aspect(double x, double y, double z)
      The proportions of the plot box (default 1, 1, 0.75), e.g., 1, 1, 1 for a cube or 2, 1, 1 for a long x axis.
    • categories

      public Plot3D categories(int axis, String... labels)
      The categories of an axis (e.g., the names of groups): the numbers of the axis are the names at the positions 0, 1, 2, ... (the box plot, the violin plot and the histogram set their categories).
      Parameters:
      axis - 0 = x, 1 = y, 2 = z
      labels - the names of the categories
      Returns:
      the plot
    • grids

      public Plot3D grids(boolean xy, boolean xz, boolean yz)
      The grids behind the data: the floor (XY) and the walls (XZ, YZ).
    • colorBarTitle

      public Plot3D colorBarTitle(String title)
      The title of the color bar (default: the title of the z axis).
    • textColors

      public Plot3D textColors(int title, int numbers, int axisTitles, int legend)
      The colors of the texts (0xRRGGBB, -1 = the color of the lines of the 3D view): the title, the numbers of the axes (and the labels of the data, e.g., the percentages of a pie chart), the titles of the axes and the legend with the color bar.
    • fonts

      public Plot3D fonts(String title, String numbers, String axisTitles, String legend)
      The font families of the texts (e.g., "Arial", "Georgia", null = Verdana): the title, the numbers of the axes (and the labels of the data), the titles of the axes and the legend with the color bar. The fonts are used in the 3D view, in the HTML export (CSS font families) and in the Blender export (the font files of the families, if found in the font folders of the system). See availableFonts.
    • font

      public Plot3D font(String family)
      The font family of all texts (e.g., "Arial", null = Verdana, see fonts).
    • availableFonts

      public static String[] availableFonts()
      Returns the names of the font families which are installed (for font and fonts).
    • textColor

      public Plot3D textColor(int rgb)
      The color of all texts (0xRRGGBB, -1 = the color of the lines of the 3D view).
    • clearLayers

      public Plot3D clearLayers()
      Removes all layers (e.g., to add the layers of the next step of a simulation, see update).
    • set

      public Plot3D set(int index, Plot3D.Layer<?> layer)
      Replaces a layer (the index of add).
    • remove

      public Plot3D remove(int index)
      Removes a layer (the index of add).
    • layerCount

      public int layerCount()
      Returns the number of the layers.
    • legend

      public Plot3D legend(boolean legend)
      Displays the legend of the layers with a label (default true).
    • add

      public Plot3D add(Plot3D.Layer<?> layer)
      Adds a layer (e.g., Plot3D.scatter(x, y, z)).
    • scatter

      public static Plot3D.Scatter scatter(double[] x, double[] y, double[] z)
      A scatter plot (spheres) of the points (x[i], y[i], z[i]).
    • line

      public static Plot3D.Line line(double[] x, double[] y, double[] z)
      A line through the points (x[i], y[i], z[i]).
    • filledLine

      public static Plot3D.FilledLine filledLine(double[] x, double[] y, double[] z)
      A line through the points filled down to the floor (e.g., several series at different y).
    • surface

      public static Plot3D.Surface surface(double[] x, double[] y, double[][] z)
      A surface of the grid z[i][j] at x[i], y[j].
    • wireframe

      public static Plot3D.Wireframe wireframe(double[] x, double[] y, double[][] z)
      A wireframe of the grid z[i][j] at x[i], y[j].
    • bars

      public static Plot3D.Bars bars(double[] x, double[] y, double[][] z)
      Bars of the grid z[i][j] at x[i], y[j] (e.g., a 2D histogram).
    • bars

      public static Plot3D.Bars bars(double[] x, double[] y, double[] z)
      Bars at the points (x[i], y[i]) with the heights z[i].
    • contour

      public static Plot3D.Contour contour(double[] x, double[] y, double[][] z)
      The contour lines of the grid z[i][j] at x[i], y[j].
    • pie

      public static Plot3D.Pie pie(double[] values, String[] labels)
      A 3D pie chart of the values (the labels are displayed in the legend).
    • lineGraph

      public static com.eco.bio7.spatial.PlotCharts.LineGraph lineGraph(double[] x, double[][] series)
      A line graph: the series of values over x (series[k][i] at x[i]), each series a line with markers at its own position in the depth (see PlotCharts.LineGraph).
    • boxplot

      public static com.eco.bio7.spatial.PlotCharts.BoxPlot boxplot(double[][] groups, String[] names)
      A box plot of groups (the values of each group, the names on the x axis, see PlotCharts.BoxPlot).
    • violin

      public static com.eco.bio7.spatial.PlotCharts.Violin violin(double[][] groups, String[] names)
      A violin plot of groups (the kernel density of the values of each group, see PlotCharts.Violin).
    • histogram

      public static com.eco.bio7.spatial.PlotCharts.Histogram histogram(double[] values)
      A histogram of values (see PlotCharts.Histogram).
    • histogram

      public static com.eco.bio7.spatial.PlotCharts.Histogram histogram(double[][] groups, String[] names)
      Histograms of groups (in the depth with the names on the y axis, see PlotCharts.Histogram).
    • area

      public static com.eco.bio7.spatial.PlotCharts.Area area(double[] x, double[][] series)
      An area chart of series over x (stacked, see PlotCharts.Area).
    • radar

      public static com.eco.bio7.spatial.PlotCharts.Radar radar(double[][] series, String[] axes)
      A radar chart: the values of the series (series[k][axis]) on the axes (without the axes of the box, see PlotCharts.Radar).
    • rose

      public static com.eco.bio7.spatial.PlotCharts.Rose rose(double[] values, String[] sectors)
      A rose chart: a value for each sector (e.g., the directions of a wind rose, see PlotCharts.Rose).
    • rose

      public static com.eco.bio7.spatial.PlotCharts.Rose rose(double[][] values, String[] sectors)
      A rose chart with classes: values[sector][class] stacked from the center (e.g., the wind speeds of a wind rose).
    • treemap

      public static com.eco.bio7.spatial.PlotCharts.Treemap treemap(double[] values, String[] labels)
      A treemap of the values (rectangles with the area of the values, see PlotCharts.Treemap).
    • show

      public Plot3D show()
      Displays the plot in the 3D view (opens the 3D perspective if necessary). The plot replaces a displayed plot.
      Returns:
      the plot
    • update

      public Plot3D update()
      Updates the displayed plot with the current layers (e.g., in each step of a simulation, also from the OpenGL thread of a model): the plot is computed again and the 3D view displays it in the next frame. The camera, the font sizes and the view are kept (the 3D view is not opened or brought to the front, see show). Fixed ranges (xRange, yRange, zRange) avoid that the axes change with the data.
      Returns:
      the plot
    • clear

      public static void clear()
      Removes the displayed plot from the 3D view (and the title, the axes and the legends of the plot).
    • setExportAction

      public static void setExportAction(boolean visible)
      Shows or hides the action "Export Plot (WebGL, Blender)" in the toolbar of the 3D view (hidden by default). The action exports the displayed plot to an HTML page with WebGL or for Blender (glTF and a Python script).
      Parameters:
      visible - true to show the action
    • exportAction

      public Plot3D exportAction(boolean visible)
      Shows the action "Export Plot (WebGL, Blender)" in the toolbar of the 3D view when the plot is displayed (see setExportAction).
      Parameters:
      visible - true to show the action
      Returns:
      the plot
    • getCurrent

      public static Plot3D getCurrent()
      Returns the displayed plot or null.
    • exportHtml

      public void exportHtml(String file) throws IOException
      Exports the plot to an HTML page with WebGL (a single file without dependencies): the plot can be rotated with the mouse and zoomed with the mouse wheel in a web browser.
      Parameters:
      file - the HTML file
      Throws:
      IOException - if the file cannot be written
    • exportGltf

      public void exportGltf(String file) throws IOException
      Exports the plot to a glTF binary file (*.glb), e.g., for Blender (File - Import - glTF 2.0): an object for each layer (named after the label) with the vertex colors, the points as spheres, the lines as tubes and the box, the grids and the axes as an object "Frame" (not for a pie chart). The texts are not part of the file (see exportBlender).
      Parameters:
      file - the glTF file (*.glb)
      Throws:
      IOException - if the file cannot be written
    • exportBlender

      public String exportBlender(String file) throws IOException
      Exports the plot for Blender: the glTF file (see exportGltf) and a Python script with the same name (*.py) which imports the file in Blender and adds the title, the axis titles and the numbers as text objects, a camera and the lights (in Blender: Scripting - Open - Run Script).
      Parameters:
      file - the glTF file (*.glb), the script is written next to it
      Returns:
      the path of the Python script
      Throws:
      IOException - if a file cannot be written