Package

co.theasi

plotly

Permalink

package plotly

Scala Plotly client

Plotly is a platform for creating and hosting plots. This library lets you create, modify and delete plots on Plotly.

Build a plot using Plot, and send that plot to the Plotly servers with draw.

import co.theasi.plotly._

val xs = Vector(1, 2, 3)
val ys = Vector(4.5, 8.5, 21.0)

val p = Plot().withScatter(xs, ys)
draw(p, "my-first-plot")

Useful links

For more information on how to build complex plot objects, read the documentation for CartesianPlot and ThreeDPlot.

For information on structuring complex figures with subplots, read the documentation for RowFigure and GridFigure.

To control how the client deals with existing files with the same name on the Plotly server, and to control the privacy options, read the documentation for writer.FileOptions

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. plotly
  2. ServerWriterWithDefaultCredentials
  3. ServerWriter
  4. ReadableImplicits
  5. WritableImplicits
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. case class Axis(options: AxisOptions) extends Product with Serializable

    Permalink
  2. case class AxisOptions(title: Option[String], tickLength: Option[Int], zeroLine: Option[Boolean], gridWidth: Option[Int], grid: Option[Boolean], line: Option[Boolean], lineColor: Option[Color], titleFont: Font, tickFont: Font, autoTick: Option[Boolean], tickSpacing: Option[Double], tickColor: Option[Color], tickLabels: Option[Boolean]) extends Product with Serializable

    Permalink
  3. case class Bar[X <: PType, Y <: PType](xs: Iterable[X], ys: Iterable[Y], options: BarOptions) extends CartesianSeries2D[X, Y] with Product with Serializable

    Permalink
  4. case class BarOptions(name: Option[String] = None) extends SeriesOptions with Product with Serializable

    Permalink
  5. case class Box[X <: PType](xs: Iterable[X], options: BoxOptions) extends CartesianSeries1D[X] with Product with Serializable

    Permalink
  6. case class BoxOptions(name: Option[String] = None) extends SeriesOptions with Product with Serializable

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

    Permalink

    Plot with Cartesian axes

    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.

  8. case class CartesianPlotOptions(xAxis: Axis, yAxis: Axis) extends Product with Serializable

    Permalink
  9. sealed trait CartesianSeries extends Series

    Permalink
  10. sealed abstract class CartesianSeries1D[X <: PType] extends CartesianSeries

    Permalink
  11. sealed abstract class CartesianSeries2D[X <: PType, Y <: PType] extends CartesianSeries

    Permalink
  12. case class Color(r: Int, g: Int, b: Int, a: Double) extends Product with Serializable

    Permalink
  13. sealed trait Colorscale extends AnyRef

    Permalink
  14. case class ColorscalePredef(s: String) extends Colorscale with Product with Serializable

    Permalink

    Colorscale predefined by Plotly

  15. trait Figure extends AnyRef

    Permalink
  16. case class FigureOptions(title: Option[String], legendOptions: LegendOptions, margins: Margins, width: Option[Int], height: Option[Int], paperBackgroundColor: Option[Color], plotBackgroundColor: Option[Color]) extends Product with Serializable

    Permalink
  17. case class Font(color: Option[Color], family: Option[List[String]], size: Option[Int]) extends Product with Serializable

    Permalink
  18. case class Grid(columns: Map[String, Iterable[PType]] = Map.empty) extends Product with Serializable

    Permalink
  19. case class GridFigure(plots: Vector[Plot], viewPorts: Vector[ViewPort], numberRows: Int, numberColumns: Int, options: FigureOptions) extends Figure with Product with Serializable

    Permalink

    Figure containing plots arranged on a grid.

    Figure containing plots arranged on a grid.

    This Figure subclass is designed for equally spaced subplots on a grid. Use the companion object's apply method to construct a new instance, specifying the number of rows and columns. For instance, val figure = GridFigure(2, 3) will build a new figure with 6 subplots, arranged in a grid with two rows and three columns. You can then use the plot method to set the content of specific sub-plots.

    import util.Random
    val xs = (0 to 100).map { i => Random.nextGaussian }
    val ys = (0 to 100).map { i => Random.nextGaussian }
    val ys2 = (0 to 100).map { i => Random.nextGaussian }
    val ys3 = (0 to 100).map { i => Random.nextGaussian }
    
    val figure = GridFigure(2, 3) // 2 rows, 3 columns
      .plot(0, 0) { CartesianPlot().withScatter(xs, ys) } // top left
      .plot(0, 1) { CartesianPlot().withScatter(xs, ys2) } // top middle
      .plot(1, 2) { CartesianPlot().withScatter(xs, ys3) } // bottom right
      .title("My grid figure")
    
    draw(figure, "grid-figure")
  20. case class IterableText[T <: PType](value: Iterable[T]) extends TextValue with Product with Serializable

    Permalink
  21. case class LegendOptions(x: Option[Double], y: Option[Double], xAnchor: Option[XAnchor.Value], yAnchor: Option[YAnchor.Value], borderColor: Option[Color], backgroundColor: Option[Color], font: Font, borderWidth: Option[Double]) extends Product with Serializable

    Permalink
  22. case class Margins(top: Option[Int] = None, right: Option[Int] = None, bottom: Option[Int] = None, left: Option[Int] = None) extends Product with Serializable

    Permalink
  23. case class MarkerOptions(size: Option[Int], color: Option[Color], symbol: Option[String], lineWidth: Option[Int], lineColor: Option[Color]) extends Product with Serializable

    Permalink
  24. case class PDouble(d: Double) extends PType with Product with Serializable

    Permalink
  25. case class PInt(i: Int) extends PType with Product with Serializable

    Permalink
  26. case class PString(s: String) extends PType with Product with Serializable

    Permalink
  27. sealed trait PType extends AnyRef

    Permalink
  28. trait Plot extends AnyRef

    Permalink
  29. trait Readable[T] extends AnyRef

    Permalink
  30. trait ReadableImplicits extends AnyRef

    Permalink
  31. case class RowFigure(impl: GridFigure) extends Figure with Product with Serializable

    Permalink

    Figure containing plots arranged in a row.

    Figure containing plots arranged in a row.

    This Figure subclass is designed for equally spaced subplots in a row. Use the companion object's apply method to construct a new instance, specifying the number of subplots. For instance, val figure = RowFigure(2) will build a new figure with two subplots in a row. You can then use the plot method to set the content of specific sub-plots.

    import util.Random
    val xs = (0 to 100).map { i => Random.nextGaussian }
    val ys = (0 to 100).map { i => Random.nextGaussian }
    val ys2 = (0 to 100).map { i => Random.nextGaussian }
    
    val figure = RowFigure(2) // 2 subplots
      .plot(0) { CartesianPlot().withScatter(xs, ys) } // left
      .plot(1) { CartesianPlot().withScatter(xs, ys2) } // right
      .title("My row figure")
    
    draw(figure, "row-figure")
  32. case class Scatter[X <: PType, Y <: PType](xs: Iterable[X], ys: Iterable[Y], options: ScatterOptions) extends CartesianSeries2D[X, Y] with Product with Serializable

    Permalink
  33. case class ScatterOptions(name: Option[String], mode: Seq[ScatterMode.Value], text: Option[TextValue], marker: MarkerOptions) extends SeriesOptions with Product with Serializable

    Permalink

    Options controlling how scatter and line plots are plotted.

  34. sealed trait Series extends AnyRef

    Permalink
  35. trait SeriesOptions extends AnyRef

    Permalink
  36. case class SinglePlotFigure(plot: Plot, options: FigureOptions) extends Figure with Product with Serializable

    Permalink

    Figure containing a single plot

    Figure containing a single plot

    val xs = Vector(1, 2, 5)
    val ys = Vector(5, 9, 11)
    
    val figure = SinglePlotFigure()
      .plot { CartesianPlot().withScatter(xs, ys) }
      .title("My awesome plot")
    
    draw(figure, "test-plot")

    Use the companion object's apply method to construct a new figure. Set the content of the plot on the figure with the plot method.

    Note that all the methods on this class return a copy of the current instance. They do not modify the instance in place. Instances of SinglePlotFigure are immutable.

  37. case class SrcText(value: String) extends TextValue with Product with Serializable

    Permalink
  38. case class StringText(value: String) extends TextValue with Product with Serializable

    Permalink
  39. case class SurfaceOptions(name: Option[String], opacity: Option[Double], showScale: Option[Boolean], colorscale: Option[Colorscale]) extends SeriesOptions with Product with Serializable

    Permalink

    Options controlling how surface plots are drawn.

    Options controlling how surface plots are drawn.

    val surfaceOptions = SurfaceOptions().opacity(0.9).colorscale("Electric")
    
    val plot = ThreeDPlot().withSurface(xs, ys, zs, surfaceOptions)
  40. case class SurfaceXYZ[X <: PType, Y <: PType, Z <: PType](xs: Iterable[X], ys: Iterable[Y], zs: Iterable[Iterable[Z]], options: SurfaceOptions) extends ThreeDSeries with Product with Serializable

    Permalink
  41. case class SurfaceZ[Z <: PType](zs: Iterable[Iterable[Z]], options: SurfaceOptions) extends ThreeDSeries with Product with Serializable

    Permalink
  42. sealed trait TextValue extends AnyRef

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

    Permalink

    Plot with 3D axes

    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.

  44. case class ThreeDPlotOptions(xAxisOptions: AxisOptions, yAxisOptions: AxisOptions, zAxisOptions: AxisOptions) extends Product with Serializable

    Permalink
  45. sealed trait ThreeDSeries extends Series

    Permalink
  46. case class ViewPort(xDomain: (Double, Double), yDomain: (Double, Double)) extends Product with Serializable

    Permalink
  47. trait Writable[T] extends AnyRef

    Permalink
  48. trait WritableImplicits extends AnyRef

    Permalink

Abstract Value Members

  1. implicit abstract val server: Server

    Permalink
    Definition Classes
    ServerWriter

Concrete Value Members

  1. object Axis extends Serializable

    Permalink
  2. object AxisOptions extends Serializable

    Permalink
  3. object CartesianPlot extends Serializable

    Permalink
  4. object CartesianPlotOptions extends Serializable

    Permalink
  5. object Color extends Product with Serializable

    Permalink
  6. object Figure

    Permalink
  7. object FigureOptions extends Serializable

    Permalink
  8. object Font extends Serializable

    Permalink
  9. object GridFigure extends Serializable

    Permalink

    Factory methods for building instances of GridFigure.

  10. object LegendOptions extends Serializable

    Permalink
  11. object MarkerOptions extends Serializable

    Permalink
  12. object Plot

    Permalink
  13. implicit object ReadableDouble extends Readable[Double]

    Permalink
    Definition Classes
    ReadableImplicits
  14. object RowFigure extends Serializable

    Permalink
  15. object ScatterMode extends Enumeration

    Permalink
  16. object ScatterOptions extends Serializable

    Permalink
  17. object SinglePlotFigure extends Serializable

    Permalink

    Factory methods for building instances of SinglePlotFigure.

  18. object SurfaceOptions extends Serializable

    Permalink
  19. object ThreeDPlot extends Serializable

    Permalink
  20. object ThreeDPlotOptions extends Serializable

    Permalink
  21. object ViewPort extends Serializable

    Permalink
  22. implicit object WritableDouble extends Writable[Double]

    Permalink
    Definition Classes
    WritableImplicits
  23. implicit object WritableInt extends Writable[Int]

    Permalink
    Definition Classes
    WritableImplicits
  24. implicit object WritableString extends Writable[String]

    Permalink
    Definition Classes
    WritableImplicits
  25. object XAnchor extends Enumeration

    Permalink
  26. object YAnchor extends Enumeration

    Permalink
  27. def draw(grid: Grid, fileName: String, fileOptions: FileOptions)(implicit server: Server): GridFile

    Permalink
    Definition Classes
    ServerWriter
  28. def draw(grid: Grid, fileName: String)(implicit server: Server): GridFile

    Permalink
    Definition Classes
    ServerWriter
  29. def draw(plot: Plot, fileName: String, fileOptions: FileOptions)(implicit server: Server): PlotFile

    Permalink
    Definition Classes
    ServerWriter
  30. def draw(plot: Plot, fileName: String)(implicit server: Server): PlotFile

    Permalink
    Definition Classes
    ServerWriter
  31. def draw(figure: Figure, fileName: String, fileOptions: FileOptions)(implicit server: Server): PlotFile

    Permalink
    Definition Classes
    ServerWriter
  32. def draw(figure: Figure, fileName: String)(implicit server: Server): PlotFile

    Permalink
    Definition Classes
    ServerWriter
  33. object emptyFont

    Permalink
  34. object emptyLegendOptions

    Permalink
  35. object emptyMargins

    Permalink
  36. package writer

    Permalink

Inherited from ServerWriter

Inherited from ReadableImplicits

Inherited from WritableImplicits

Inherited from AnyRef

Inherited from Any

Ungrouped