Skip to content

Instantly share code, notes, and snippets.

@drdozer
Created November 29, 2016 11:47
Show Gist options
  • Save drdozer/4d3aa89ba34671b5ad23a191e3a16eb0 to your computer and use it in GitHub Desktop.
Save drdozer/4d3aa89ba34671b5ad23a191e3a16eb0 to your computer and use it in GitHub Desktop.
Sketch of some ideas for data plotting DSL
// build n histograms as (n, histogram) pairs
val histograms = for {
n <- 1 to N
} yield (
n,
histogram(
dataPoints = for
{
t <- (min of time from tradeHistory) to (max of time from tradeHistory - n)
} yield price of tradeHistory(t + n) - price of tradeHistory(t)
)
)
// x ranges over N
val xAxisRange = orderedValues(1 to N)
// y ranges from 0 to the maximum histogram frequency
val yAxisRange = orderedValues(0 to max of (for {
h <- histograms
} yield h.valueWithMaximumFrequency)
// each histogram is plotted 3 pixles wide
val x3 = continuousAxis(0 to 2)
// the whole x axis is plotted in discrete bins, one per xAxisRange, 3 pixles per bin
val xAxis = discreteAxis(xAxisRange, valueWidth = x3.size)
// y axis is a continuous scaling of the y axis data range
val yAxis = continuousAxis(yAxisRange)
// plot an x/y chart of
plot(
xAxis,
yAxis,
x = histograms._1
y = histograms._2,
// sub-plots that scatter histogrammed datapoints across the local x axis
plotWith = y map (h => plot(x3, yAxis, x = random(0 to 2), y = h))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment