Class Plot3D
java.lang.Object
com.eco.bio7.spatial.Plot3D
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 ClassesModifier and TypeClassDescriptionstatic final classBars (boxes) from the floor (or 0) to the values.static final classThe contour lines of a grid (at their heights or on the floor).static final classA line filled down to the floor (a ribbon).static classPlot3D.Layer<T extends Plot3D.Layer<T>>A layer of a plot with the common settings: a label (for the legend), a color, a color map and the transparency.static classA line through the points.static final classA 3D pie chart (without axes, the labels in the legend and the percentages at the slices).static final classA scatter plot: spheres at the points.static final classA surface of a grid (smooth shading, optional with the lines of the grid).static final classA wireframe of a grid. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int[]The colors of the layers without a color (like the categories of R or matplotlib). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(Plot3D.Layer<?> layer) Adds a layer (e.g., Plot3D.scatter(x, y, z)).static com.eco.bio7.spatial.PlotCharts.Areaarea(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).axisTitles(String x, String y, String z) The titles of the axes (null = X, Y, Z).static Plot3D.Barsbars(double[] x, double[] y, double[] z) Bars at the points (x[i], y[i]) with the heights z[i].static Plot3D.Barsbars(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.BoxPlotA 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 voidclear()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).colorBarTitle(String title) The title of the color bar (default: the title of the z axis).static Plot3D.Contourcontour(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).exportBlender(String file) 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).voidexportGltf(String file) 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).voidexportHtml(String file) 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.static Plot3D.FilledLinefilledLine(double[] x, double[] y, double[] z) A line through the points filled down to the floor (e.g., several series at different y).The font family of all texts (e.g., "Arial", null = Verdana, see fonts).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 Plot3DReturns 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.Histogramhistogram(double[] values) A histogram of values (see PlotCharts.Histogram).static com.eco.bio7.spatial.PlotCharts.HistogramHistograms of groups (in the depth with the names on the y axis, see PlotCharts.Histogram).intReturns the number of the layers.legend(boolean legend) Displays the legend of the layers with a label (default true).static Plot3D.Lineline(double[] x, double[] y, double[] z) A line through the points (x[i], y[i], z[i]).static com.eco.bio7.spatial.PlotCharts.LineGraphlineGraph(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).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).static Plot3D.PieA 3D pie chart of the values (the labels are displayed in the legend).static com.eco.bio7.spatial.PlotCharts.RadarA 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.RoseA 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.RoseA rose chart: a value for each sector (e.g., the directions of a wind rose, see PlotCharts.Rose).static Plot3D.Scatterscatter(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 voidsetExportAction(boolean visible) Shows or hides the action "Export Plot (WebGL, Blender)" in the toolbar of the 3D view (hidden by default).show()Displays the plot in the 3D view (opens the 3D perspective if necessary).static Plot3D.Surfacesurface(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.The title of the plot (lines separated with \n).static com.eco.bio7.spatial.PlotCharts.TreemapA treemap of the values (rectangles with the area of the values, see PlotCharts.Treemap).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.static com.eco.bio7.spatial.PlotCharts.ViolinA violin plot of groups (the kernel density of the values of each group, see PlotCharts.Violin).static Plot3D.Wireframewireframe(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).
-
Field Details
-
CATEGORY_COLORS
public static final int[] CATEGORY_COLORSThe colors of the layers without a color (like the categories of R or matplotlib).
-
-
Constructor Details
-
Plot3D
public Plot3D()
-
-
Method Details
-
title
-
axisTitles
-
logAxes
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
-
xRange
The range of the x axis (instead of the range of the data). -
yRange
The range of the y axis (instead of the range of the data). -
zRange
The range of the z axis (instead of the range of the data). -
aspect
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
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 = zlabels- the names of the categories- Returns:
- the plot
-
grids
The grids behind the data: the floor (XY) and the walls (XZ, YZ). -
colorBarTitle
-
textColors
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
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
-
availableFonts
Returns the names of the font families which are installed (for font and fonts). -
textColor
The color of all texts (0xRRGGBB, -1 = the color of the lines of the 3D view). -
clearLayers
Removes all layers (e.g., to add the layers of the next step of a simulation, see update). -
set
Replaces a layer (the index of add). -
remove
Removes a layer (the index of add). -
layerCount
public int layerCount()Returns the number of the layers. -
legend
Displays the legend of the layers with a label (default true). -
add
Adds a layer (e.g., Plot3D.scatter(x, y, z)). -
scatter
A scatter plot (spheres) of the points (x[i], y[i], z[i]). -
line
A line through the points (x[i], y[i], z[i]). -
filledLine
A line through the points filled down to the floor (e.g., several series at different y). -
surface
A surface of the grid z[i][j] at x[i], y[j]. -
wireframe
A wireframe of the grid z[i][j] at x[i], y[j]. -
bars
Bars of the grid z[i][j] at x[i], y[j] (e.g., a 2D histogram). -
bars
Bars at the points (x[i], y[i]) with the heights z[i]. -
contour
The contour lines of the grid z[i][j] at x[i], y[j]. -
pie
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
A box plot of groups (the values of each group, the names on the x axis, see PlotCharts.BoxPlot). -
violin
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
A radar chart: the values of the series (series[k][axis]) on the axes (without the axes of the box, see PlotCharts.Radar). -
rose
A rose chart: a value for each sector (e.g., the directions of a wind rose, see PlotCharts.Rose). -
rose
A rose chart with classes: values[sector][class] stacked from the center (e.g., the wind speeds of a wind rose). -
treemap
A treemap of the values (rectangles with the area of the values, see PlotCharts.Treemap). -
show
Displays the plot in the 3D view (opens the 3D perspective if necessary). The plot replaces a displayed plot.- Returns:
- the plot
-
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
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
Returns the displayed plot or null. -
exportHtml
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
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
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
-