Class/Object

co.theasi.plotly

CartesianPlot

Related Docs: object CartesianPlot | package plotly

Permalink

case class CartesianPlot(series: Vector[CartesianSeries], options: CartesianPlotOptions) extends Plot with Product with Serializable

Plot with Cartesian axes

Example usage

This class draws a sub-plot on Cartesian axes. This can be used to draw bar charts, scatter plots, box plots, contour plots etc.: anything that has an x- and a y-axis.

CartesianPlot instances can be sent directly to Plotly:

val xs = Vector(1, 2, 5)
val ys = Vector(2, 4, 9)
val plot = CartesianPlot().withScatter(xs, ys)
draw(plot, "my-scatter-plot")

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

val xs = Vector(1, 2, 5)
val ys1 = Vector(2, 4, 9)
val ys2 = Vector(2, 6, 12)

val figure = RowFigure(2) // 2 sub-plots next to each other
  .plot(0) { CartesianPlot().withScatter(xs, ys1) } // left subplot
  .plot(1) { CartesianPlot().withScatter(xs, ys2) } // right subplot

draw(figure, "multiple-plots")

Multiple lines

CartesianPlot instances support multiple series:

val xs = Vector(1, 2, 3)
val ys1 = xs.map { 2 * _ }
val ys2 = xs.map { -2 * _ }

val p = CartesianPlot()
  .withScatter(xs, ys1, ScatterOptions().name("series-1"))
  .withScatter(xs, ys2, ScatterOptions().name("series-2"))

draw(p, "multiple-series")

The immutable builder pattern

When you call the .withScatter method on a CartesianPlot object, it returns a new plot with the new data series added. CartesianPlot instances are immutable. Thus, the following will not work:

// Not what you want!
val p = CartesianPlot().withScatter(xs, ys1)
p.withScatter(xs, ys2) // No: this does not modify 'p' in place!

draw(p, "my-other-plot")

Do this instead:

val p = CartesianPlot().withScatter(xs, ys1)
val newPlot = p.withScatter(xs, ys2)

draw(newPlot, "my-other-plot")

Or, better yet, use chaining to avoid creating temporary variables:

val p = CartesianPlot()
  .withScatter(xs, ys1)
  .withScatter(xs, ys2)

draw(p, "another-plot")

All methods in this class work in the same way: they return a new instance of CartesianPlot. 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. CartesianPlot
  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 CartesianPlot(series: Vector[CartesianSeries], options: CartesianPlotOptions)

    Permalink

Type Members

  1. type OptionType = CartesianPlotOptions

    Permalink
    Definition Classes
    CartesianPlotPlot

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: CartesianPlotOptions

    Permalink
    Definition Classes
    CartesianPlotPlot
  14. val series: Vector[CartesianSeries]

    Permalink
    Definition Classes
    CartesianPlotPlot
  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 withBar[X, Y](xs: Iterable[X], ys: Iterable[Y])(implicit arg0: Writable[X], arg1: Writable[Y]): CartesianPlot

    Permalink

    Add a bar series to this plot.

  20. def withBox[X](xs: Iterable[X])(implicit arg0: Writable[X]): CartesianPlot

    Permalink

    Add a box plot to this plot.

  21. def withScatter[X, Y](xs: Iterable[X], ys: Iterable[Y], options: ScatterOptions): CartesianPlot

    Permalink

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

    [use case]

    Add a scatter plot to this plot.

    xs

    The 'xs' series. This can be an iterable of any type T, provided an instance of the typeclass 'Writable[T]' exists.

    ys

    The 'ys' series.

    options

    (optional) Options controlling the plot style.

    returns

    Copy of this plot with the scatter series added.

    Full Signature

    def withScatter[X, Y](xs: Iterable[X], ys: Iterable[Y], options: ScatterOptions = ScatterOptions())(implicit arg0: Writable[X], arg1: Writable[Y]): CartesianPlot

    Example:
    1. val xs = Vector(1.0, 2.0, 3.0)
      val ys1 = xs.map { _ * 2.0 }
      val ys2 = xs.map { _ * (-2.0) }
      val p = CartesianPlot()
        .withScatter(xs, ys1)
        .withScatter(xs, ys2, ScatterOptions().name("series-2"))
  22. def xAxisOptions(newAxisOptions: AxisOptions): CartesianPlot

    Permalink

    Set the x-axis options for this plot.

  23. def yAxisOptions(newAxisOptions: AxisOptions): CartesianPlot

    Permalink

    Set the y-axis options for this plot.

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Plot

Inherited from AnyRef

Inherited from Any

Ungrouped