-
Notifications
You must be signed in to change notification settings - Fork 8
Visualize
This package is part of the Axle domain specific language.
The show
function is available in the axle.visualize._
package.
It can be applied to several types of Axle objects.
That package also contains functions for creating files from the images: png
, jpeg
, gif
, bmp
.
For example:
show(plot)
png(plot, "plot.png")
axle.visualize.Plot
import util.Random
import collection._
import math.{ Pi, cos, sin }
import axle.visualize._
import axle.visualize.Plottable._
import org.joda.time.DateTime
val now = new DateTime()
def randomTimeSeries(i: Int) = {
val (phase, amp, f) = (Random.nextDouble, Random.nextDouble, Random.nextDouble)
("series %d %1.2f %1.2f %1.2f".format(i, phase, amp, f),
new immutable.TreeMap[DateTime, Double]() ++
(0 to 100).map(j => (now.plusMinutes(2 * j) -> amp * sin(phase + (j / (10 * f))))).toMap)
}
val plot = new Plot((0 until 20).map(i => randomTimeSeries(i)).toList, true,
title = Some("Random Waves"), xAxis = 0.0, xAxisLabel = Some("time (t)"),
yAxis = now, yAxisLabel = Some("a * sin(p + t/10f)"))
show(plot)
The following example dataset:
val fruits = Vector("apple", "banana", "coconut")
val years = Vector(2011, 2012)
val sales = Map(
("apple", 2011) -> 43.0,
("apple", 2012) -> 83.8,
("banana", 2011) -> 11.3,
("banana", 2012) -> 77.9,
("coconut", 2011) -> 88.0,
("coconut", 2012) -> 10.1
)
Can be grouped in two ways to produce bar charts:
import axle.visualize._
val chart = BarChart(
fruits,
years,
(fruit: String, year: Int) => sales((fruit, year)),
xAxis = 0.0,
title = Some("fruit sales")
)
show(chart)
Or:
import axle.visualize._
val chart = BarChart(
years,
fruits,
(year: Int, fruit: String) => sales((fruit, year)),
xAxis = 0.0,
title = Some("fruit sales")
)
show(chart)
Supplying a refresher
to the BarChart will cause the data to be recomputed.
The first half of the refresher
is a function that takes the previous data and returns the new data.
The second half is an interval (of type Time.Q
that denotes the period at which values are recomputed.
This example keeps the "bar" value steady at 1.0 while assigning a new random Double (between 0 and 1) to "foo" every second.
The visualizing frame polls for updates at a rate of approximately 24 Hz (every 42 ms).
import util.Random.nextDouble
import axle.visualize._
import axle.quanta._
import Time._
val groups = Vector("foo", "bar")
val slices = Vector("bippy")
val initial = Map(("foo", "bippy") -> 1d, ("bar", "bippy") -> 1d)
val tick = (previous: Map[(String, String), Double]) => previous + (("foo", "bippy") -> nextDouble)
val chart = BarChart(
groups,
slices,
initial,
xAxis = 0d,
title = Some("random"),
refresher = Some(tick, 1 *: second)
)
show(chart)
TODO: show example of 2-feature KMeans clustering
TODO: show directed and undirected graph visualizations