Learn R Programming

barsurf (version 0.5.0)

03_plot_contour_3d: Contour Plots in 3D

Description

Contour plots in 3d (for functions of three variables), with one or more isosurfaces.

Usage

#x-y-fv version
#(main argument is an array, or a list of arrays)
plot_contour_3d (x, y, z, fv, fb, …,
    wire.frame=FALSE,
    main, xlab="x", ylab="y", xat, yat, xlabs, ylabs,
    xlim, ylim, zlim,
    axes=TRUE, arrows=TRUE,
    ncontours=2, wire.frame.color="#808080", iso.colors)

#functional version #(which calls the x-y-fv version above) plotf_contour_3d (f, xlim, ylim=xlim, zlim=xlim, …, n=20, maximal=FALSE, base.contours=FALSE, rear.contours=FALSE, pconstants)

#functional version #(which calls plotf_contour_3d above) nested_isosurfaces (f, xlim, ylim=xlim, zlim=xlim, …, nfirst=30, nlast=15)

Arguments

x, y, z

Sorted numeric vectors of x, y and z coordinates, or lists of such vectors. If lists, then their lengths need to equal the number of isosurfaces. (If fv is an array, then x, y and z are optional).

fv

A 3-dimensional numeric array, or a list of such arrays. If fv is a list, then its length needs to equal the number of isosurfaces.

fb

Numeric vector of function values (or "levels"), for contour/isosurface values. This is optional, however in general, you need to specify this for good plots. Note that if isosurfaces are nested, the first isosurface (for the first fb value) is assumed to be inside the second isosurface (for the second fb value), the second inside the third, and so on. In general, if you need to plot functions with minimal (low-valued) focal points, fb values should be increasing, and if need to plot functions with maximal (high-valued) focal points, fb values should be decreasing.

wire.frame

Logical, include the wire.frame lines.

main, xlab, ylab

Strings, main/axes titles.

xat, yat

Optional numeric vectors, the x and y axes tick points.

xlabs, ylabs

Optional character vectors, the x and y axes tick labels. In 3D plots, ignored unless axes is true and arrows is false.

xlim, ylim

Length-2 numeric vectors, the x and y ranges. Note that the package has only been tested with ascending values.

zlim

Length-2 numeric vector, the z (vertical) range.

axes

Logical vector of length one or two, if true plot reference arrows or axis ticks with labels.

arrows

Logical vector of length one or two, (subject to axes, above) if true, plot reference arrows, if false, use axis ticks with labels.

ncontours

Integer, the number of contours/isosurfaces, ignored if fb supplied.

wire.frame.color

Optional string, giving the wire frame color.

iso.colors

Character vector (with the same length as the number of isosurfaces), giving the (initial) isosurface colors. Optional for up to three isosurfaces.

f

A numeric-valued function of three variables (x, y, and z).

n

An integer vector of length one or three (giving the number of grid points), or list of such vectors (giving the number of grid points for each isosurface). If a list, its length needs to equal the number of isosurfaces.

nfirst, nlast

Integer vectors of length one or three (giving the number of grid points), for the first and last isosurfaces.

maximal

Logical, if true assume maximal (high-valued) focal points, that is, any focal points within the plot have higher function/array values than their surrounding values. This determines whether the default fb values are ascending or descending. And is ignored if the fb vector is supplied.

base.contours

Logical, include contour lines on the base panel of the plot.

rear.contours

Logical, include contour lines on the rear panels of the plot.

pconstants

Optional length-3 numeric vector of panel constants. Defaults to the midpoints of xlim, ylim and zlim. Refer to details and examples.

In the x-y-fv version, ignored.

Details

These functions require the misc3d package to be installed, and be on the search path.

These functions are similar to plot_cfield and plot_surface. (So, please refer to those functions for background information).

In plot_contours_3d, fv is a 3-dimensional array, or a list of such arrays.

x, y and z can be vectors, or lists of vectors.

Increasing along the first array dimension corresponds to increasing x values. Increasing along the second array dimension corresponds to increasing y values. And increasing along the third array dimension corresponds to increasing z values.

x and y (the first two variables) have the same interpretation as they do in plot_surface. z (the third variable) gives the vertical position. Except that x, y and z describe coordinates of the fv array, not the resulting isosurfaces.

If x, y, z, fv or n are lists, then their lengths need to equal the number of isosurfaces, and each list element applies to one isosurface.

Unlike other plots in this package, the isosurfaces don't use color interpolation, however, a small amount of random color variation is added.

The plotf_contour_3d function calls plot_contour_3d, but computes the x, y, z and fv values.

Optionally, 2D contour lines may added to the base panel and rear panels.

If necessary, a vector of panel constants (pconstants) is used.

A matrix is computed by evaluating the function, f, while holding the third variable constant (at the third panel constant). This matrix is used to compute the base contours. Likewise, the first variable is held constant (at the first panel constant) for the right rear panel, and the second variable is held constant (at the second panel constant) for the left rear panel.

The nested_isosurfaces function calls the plotf_contour_3d function, but computes the grid size for each isosurface.

Unlike the other two functions, it needs at least two isosurfaces, and assumes that the first isosurface(s) is/are inside the second, and that the second isosurface(s) is/are inside the third, and so on.

By default, the resolution of fv is highest for the first isosurface, and each fv array has a progressively lower resolution.

Resulting plots should result in smaller file sizes, and render more quickly.

References

Refer to the vignette for an overview, references and better examples.

See Also

Plots of scalar fields over two variables: plot_dfield, plot_cfield

Other plots of scalar fields over three variables: plot_cfield_3d

Other functions: litmus, litmus.fit

Examples

Run this code
# NOT RUN {
library (misc3d)

plotf_contour_3d (bispherical.dist, c (-3, 3),, c (-2, 2), fb = c (0.5, 1, 1.75),
    base.contours=TRUE)

#panel contours condition on x=1, y=1, z=0
nested_isosurfaces (bispherical.dist, c (-3, 3),, c (-2, 2), fb = c (0.5, 1, 1.75),
    base.contours=TRUE, rear.contours=TRUE,
    arrows=FALSE,
    pconstants = c (1, 1, 0) )
# }

Run the code above in your browser using DataLab