2d Plotting Library in pure Scala (including scala-js)

Renders the same plots both to vector (pdf, svg, eps) and raster formats (png, jpg), java Graphics2D or Html5 Canvas. Runs on the JVM or in the browser with minimal dependencies.

Output formats on the JVM:

Output formats in the browser:

Creates scatter, line, contour, raster, barplots and boxplots, histograms, density plots. Creates composite figure of multiple plots

Minimal external dependencies (VectorGraphics2D for PDF output, ScalaTags for SVG).

Convenient interface for SADDLE data structures.

Can work from streams of data without keeping them in memory, thus can create plots from huge files to raster images.

Easily extendible via simple to use typesafe scene graph.

Usage

JVM


    import org.nspl._
    import awtrenderer._
    val x : Seq[Double] = Seq(1d,2d,3d)
    val y : Seq[Double] = Seq(6d,7d,10d)
    val plot = xyplot(x -> y)(
      ylab = "y",
      xlab = "x",
      main = "main"
    )
    show(plot)

Browser


  import org.nspl._
  import canvasrenderer._
  import org.scalajs.dom
  import org.scalajs.dom.html

  val canvas = dom.document.createElement("canvas").asInstanceOf[html.Canvas]

  val x : Seq[Double] = Seq(1d,2d,3d)
  val y : Seq[Double] = Seq(6d,7d,10d)
  val plot = xyplot(x -> y)(
    ylab = "y",
    xlab = "x",
    main = "main"
  )
  render(plot, canvas, 800)

For more see canvas/src/main/scala/org/nspl/test.scala for Html5 Canvas examples and saddle/src/test/scala/plots/plots.test.scala for JVM examples.

Examples

PDF

Open

SVG - VectorGraphics2d

SVG - Scalatags

PNG

Canvas

SVG - scala-js