Skip to content

Instantly share code, notes, and snippets.

@dramage
Created October 14, 2011 21:58
Show Gist options
  • Save dramage/1288473 to your computer and use it in GitHub Desktop.
Save dramage/1288473 to your computer and use it in GitHub Desktop.
Scalala scatter plot example
import scalala.library.Plotting._
import scalala.tensor.dense.DenseVector
import java.awt.Color
import scalala.library.plotting.GradientPaintScale
val x = DenseVector.randn(10)
val y = DenseVector.randn(10)
val s = DenseVector.rand(10) :/ 5
val labels : PartialFunction[Int,String] =
Map(1->"Red", 4->"Blue")
val tips : PartialFunction[Int,String] =
{case i : Int => i.toString}
figure(1)
val literalColors : PartialFunction[Int,Color] =
Map(1->Color.RED, 4->Color.BLUE) orElse { case x : Int => Color.WHITE }
scatter(x, y, s, literalColors, labels=labels, tips=tips)
figure(2)
val c = DenseVector.rand(10);
val paintScale = GradientPaintScale(0.0, 1.0)
val scaleColors = Map() ++ (0 until c.length).map(i => (i, paintScale(c(i))));
scatter(x, y, s, scaleColors, labels = labels, tips = tips)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment