# 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

Open

### SVG - VectorGraphics2d ### SVG - Scalatags ### PNG
{"ft_lang_label":"__label__en","ft_lang_prob":0.5988755,"math_prob":0.9489797,"size":1528,"snap":"2021-04-2021-17","text_gpt3_token_len":420,"char_repetition_ratio":0.10367454,"word_repetition_ratio":0.2264151,"special_character_ratio":0.26112565,"punctuation_ratio":0.19354838,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9761451,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,1,null,1,null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-24T01:40:17Z\",\"WARC-Record-ID\":\"<urn:uuid:6e29f2f4-d747-472d-826d-3c73b645f80d>\",\"Content-Length\":\"5374\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d71839e6-52e4-4a2e-b338-eddec329d33b>\",\"WARC-Concurrent-To\":\"<urn:uuid:088107f1-a8a7-4363-b17f-c3197635c65a>\",\"WARC-IP-Address\":\"185.199.110.153\",\"WARC-Target-URI\":\"https://pityka.github.io/nspl/\",\"WARC-Payload-Digest\":\"sha1:JVCYVXPFY2ZI7QRYJ34VUURCYNLKOKFL\",\"WARC-Block-Digest\":\"sha1:7FKUWYCHMP5IKX2HBPNJMVJT3YK4Y4XM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610703544403.51_warc_CC-MAIN-20210124013637-20210124043637-00358.warc.gz\"}"}