Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 8, 2023 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/4d538f5d1c25f184cc918fd35a53987a to your computer and use it in GitHub Desktop.
Save dacr/4d538f5d1c25f184cc918fd35a53987a to your computer and use it in GitHub Desktop.
first example with the breeze data visualization / published by https://github.com/dacr/code-examples-manager #397850d8-c2c7-44ae-a18b-3708ceba3704/7d50754dbcb05ad7cea89ef6bd7d35cc83897f7c
// summary : first example with the breeze data visualization
// keywords : plotting, breeze, math
// publish : gist
// authors : breeze documentation
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : 397850d8-c2c7-44ae-a18b-3708ceba3704
// created-on : 2020-10-11T15:05:16Z
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.2.2"
//> using dep "org.scalanlp::breeze:2.1.0"
//> using dep "org.scalanlp::breeze-viz:2.1.0"
// ---------------------
// breeze viz documentation : https://github.com/scalanlp/breeze/wiki/Quickstart
// Very interesting API :)
import breeze.linalg.*
import breeze.plot.*
import breeze.stats.distributions.*
import breeze.stats.distributions.Rand.VariableSeed.randBasis
val f = Figure()
val p = f.subplot(0)
val x = linspace(0.0, 10.0, 1000)
p += plot(x, x ^:^ 2.0, name = "a")
p += plot(x, x ^:^ 3.0, name = "b", style = '.')
p.xlabel = "x axis"
p.ylabel = "y axis"
p.legend = true
//f.saveas("lines.png") // save current figure as a .png, eps and pdf also supported
val p2 = f.subplot(2, 1, 1)
val g = breeze.stats.distributions.Gaussian(0, 1)
p2 += hist(g.sample(100000), 100)
p2.title = "A normal distribution"
f.saveas("subplots.png")
scala.io.StdIn.readLine("Press enter to quit")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment