Class/Object

co.theasi.plotly

ThreeDPlot

Related Docs: object ThreeDPlot | package plotly

Permalink

case class ThreeDPlot(series: Vector[Series], options: ThreeDPlotOptions) extends Plot with Product with Serializable

Plot with 3D axes

Example usage

This class represents plots with 3D Cartesian axes. This can be used to draw 3D surface plots.

ThreeDPlot instances can be sent directly to Plotly:

val zs = Vector(
  Vector(1.0, 2.0, 1.0),
  Vector(5.0, 4.0, 5.0),
  Vector(1.0, 2.0, 1.0)
)

val plot = ThreeDPlot().withSurface(zs)
draw(plot, "my-3d-plot")

They can also be embedded in Figure instances for more complex plot layouts:

val zs1 = Vector(
  Vector(1.0, 2.0, 1.0),
  Vector(5.0, 4.0, 5.0),
  Vector(1.0, 2.0, 1.0)
)

val zs2 = zs1.map { row => row.map { _ - 2.0 } }

val figure = RowFigure(2) // 2 sub-plots next to each other
  .plot(0) { ThreeDPlot().withSurface(zs1) } // left sub-plot
  .plot(1) { ThreeDPlot().withSurface(zs2) } // right sub-plot

draw(figure, "3d-subplots")

Surface plots

Add a surface plot with the withSurface method:

val xs = Vector(-1.0, 0.0, 1.0)
val ys = Vector(0.0, 10.0)

val zs = Vector(
  Vector(1.0, 2.0, 1.0),
  Vector(5,0, 4.0, 5.0)
)

val p = ThreeDPlot().withSurface(xs, ys, zs)

The z-values are assumed to be nested iterables, oriented such that zs(0)(1) is the value of z at xs(1) and ys(0).

You can also pass in options to control how the surface is represented:

val p = ThreeDPlot().withSurface(xs, ys, zs, SurfaceOptions().opacity(0.4))

See the documentation for SurfaceOptions for a list of available options.

.withSurface also supports passing a zs iterable without xs and ys. This is equivalent to having xs = (0 to zs(0).size) and ys = (0 to zs.size).

Multiple surfaces

ThreeDPlot instances support multiple surfaces:

val zs1 = Vector(
  Vector(1.0, 2.0, 1.0),
  Vector(5.0, 4.0, 5.0),
  Vector(1.0, 2.0, 1.0)
)

val zs2 = zs1.map { row => row.map { _ - 2.0 } }

val p = ThreeDPlot()
  .withSurface(zs1, SurfaceOptions().name("top"))
  .withSurface(zs2, SurfaceOptions().name("bottom"))

The immutable builder pattern

When you call the .withSurface method on a ThreeDPlot object, it returns a new plot with the series added. ThreeDPlot instances are immutable. Thus, the following does not work as expected:

// Not what you want!
val plot = ThreeDPlot().withSurface(zs)
plot.withSurface(zs2) // No: this does not modify 'plot' in place!

You should chain calls to withSurface instead:

val plot = ThreeDPlot()
  .withSurface(zs1)
  .withSurface(zs2)

All methods in this class work in the same way: they return a new instance of ThreeDPlot. This pattern is called the immutable builder pattern: it is a variant of the common builder pattern adapted for immutable objects.

Linear Supertypes
Serializable, Serializable, Product, Equals, Plot, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ThreeDPlot
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. Plot
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ThreeDPlot(series: Vector[Series], options: ThreeDPlotOptions)

    Permalink

Type Members

  1. type OptionType = ThreeDPlotOptions

    Permalink
    Definition Classes
    ThreeDPlotPlot

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  8. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  9. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  10. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  11. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  12. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  13. val options: ThreeDPlotOptions

    Permalink
    Definition Classes
    ThreeDPlotPlot
  14. val series: Vector[Series]

    Permalink
    Definition Classes
    ThreeDPlotPlot
  15. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  16. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  17. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. def withSurface[X, Y, Z](xs: Iterable[X], ys: Iterable[Y], zs: Iterable[Iterable[Z]]): ThreeDPlot

    Permalink

    [use case] Add a surface plot to this plot.

    [use case]

    Add a surface plot to this plot.

    zs

    The values of z. This is an iterable of iterables of any type T, provided an instance of the typeclass Writable[T] exists. The values of zs are oriented such that zs(0)(1) corresponds to the value of z at xs(1) and ys(0).

    returns

    Copy of this plot with the surface added.

    Full Signature

    def withSurface[X, Y, Z](xs: Iterable[X], ys: Iterable[Y], zs: Iterable[Iterable[Z]])(implicit arg0: Writable[X], arg1: Writable[Y], arg2: Writable[Z]): ThreeDPlot

  20. def withSurface[X, Y, Z](xs: Iterable[X], ys: Iterable[Y], zs: Iterable[Iterable[Z]], options: SurfaceOptions): ThreeDPlot

    Permalink

    [use case] Add a surface plot to this plot.

    [use case]

    Add a surface plot to this plot.

    zs

    The values of z. This is an iterable of iterables of any type T, provided an instance of the typeclass Writable[T] exists. The values of zs are oriented such that zs(0)(1) corresponds to the value of z at xs(1) and ys(0).

    options

    Options controlling the style in which the surface is drawn.

    returns

    Copy of this plot with the surface added.

    Full Signature

    def withSurface[X, Y, Z](xs: Iterable[X], ys: Iterable[Y], zs: Iterable[Iterable[Z]], options: SurfaceOptions)(implicit arg0: Writable[X], arg1: Writable[Y], arg2: Writable[Z]): ThreeDPlot

  21. def withSurface[Z](zs: Iterable[Iterable[Z]]): ThreeDPlot

    Permalink

    [use case] Add a surface plot to this plot with default x and y.

    [use case]

    Add a surface plot to this plot with default x and y.

    This adds a surface plot where x and y values are assumed to range from 0 to zs(0).size and 0 to zs.size respectively.

    zs

    The values of z. This is an iterable of iterables of any type T, provided an instance of the typeclass Writable[T] exists. The values of zs are oriented such that zs(0)(1) corresponds to the value of z at x = 1 and y = 0.

    returns

    Copy of this plot with the surface added.

    Full Signature

    def withSurface[Z](zs: Iterable[Iterable[Z]])(implicit arg0: Writable[Z]): ThreeDPlot

  22. def withSurface[Z](zs: Iterable[Iterable[Z]], options: SurfaceOptions): ThreeDPlot

    Permalink

    [use case] Add a surface plot to this plot with default x and y.

    [use case]

    Add a surface plot to this plot with default x and y.

    This adds a surface plot where x and y values are assumed to range from 0 to zs(0).size and 0 to zs.size respectively.

    zs

    The values of z. This is an iterable of iterables of any type T, provided an instance of the typeclass Writable[T] exists. The values of zs are oriented such that zs(0)(1) corresponds to the value of z at x = 1 and y = 0.

    options

    Options controlling the style in which the surface is drawn.

    returns

    Copy of this plot with the surface added.

    Full Signature

    def withSurface[Z](zs: Iterable[Iterable[Z]], options: SurfaceOptions)(implicit arg0: Writable[Z]): ThreeDPlot

  23. def xAxisOptions(newAxisOptions: AxisOptions): ThreeDPlot

    Permalink

    Set options for the x-axis

    Set options for the x-axis

    newAxisOptions

    The new option values.

    returns

    Copy of this plot with the new axis options set.

    Example:
    1. val zs = Vector.tabulate(3, 4) { (i, j) => util.Random.nextDouble }
      val p = ThreeDPlot()
        .withSurface(zs)
        .xAxisOptions(AxisOptions().title("x-axis").noZeroLine)
        .yAxisOptions(AxisOptions().title("y-axis").titleColor(255, 0, 0))
        .zAxisOptions(AxisOptions().title("z-axis").noGrid)
  24. def yAxisOptions(newAxisOptions: AxisOptions): ThreeDPlot

    Permalink

    Set options for the y-axis

    Set options for the y-axis

    newAxisOptions

    The new option values.

    returns

    Copy of this plot with the new axis options set.

    Example:
    1. val zs = Vector.tabulate(3, 4) { (i, j) => util.Random.nextDouble }
      val p = ThreeDPlot()
        .withSurface(zs)
        .xAxisOptions(AxisOptions().title("x-axis").noZeroLine)
        .yAxisOptions(AxisOptions().title("y-axis").titleColor(255, 0, 0))
        .zAxisOptions(AxisOptions().title("z-axis").noGrid)
  25. def zAxisOptions(newAxisOptions: AxisOptions): ThreeDPlot

    Permalink

    Set options for the z-axis

    Set options for the z-axis

    newAxisOptions

    The new option values.

    returns

    Copy of this plot with the new axis options set.

    Example:
    1. val zs = Vector.tabulate(3, 4) { (i, j) => util.Random.nextDouble }
      val p = ThreeDPlot()
        .withSurface(zs)
        .xAxisOptions(AxisOptions().title("x-axis").noZeroLine)
        .yAxisOptions(AxisOptions().title("y-axis").titleColor(255, 0, 0))
        .zAxisOptions(AxisOptions().title("z-axis").noGrid)

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Plot

Inherited from AnyRef

Inherited from Any

Ungrouped