Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Commit 6c647d8

Browse files
committed
Add plotting API version of anscombe example
1 parent 48a0a51 commit 6c647d8

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package io.continuum.bokeh
2+
package examples
3+
package plotting
4+
5+
import breeze.linalg.{DenseMatrix,DenseVector,linspace}
6+
7+
import thirdparty._
8+
9+
object Anscombe extends Example {
10+
val anscombe_quartet = DenseMatrix(
11+
(10.0, 8.04, 10.0, 9.14, 10.0, 7.46, 8.0, 6.58),
12+
( 8.0, 6.95, 8.0, 8.14, 8.0, 6.77, 8.0, 5.76),
13+
(13.0, 7.58, 13.0, 8.74, 13.0, 12.74, 8.0, 7.71),
14+
( 9.0, 8.81, 9.0, 8.77, 9.0, 7.11, 8.0, 8.84),
15+
(11.0, 8.33, 11.0, 9.26, 11.0, 7.81, 8.0, 8.47),
16+
(14.0, 9.96, 14.0, 8.10, 14.0, 8.84, 8.0, 7.04),
17+
( 6.0, 7.24, 6.0, 6.13, 6.0, 6.08, 8.0, 5.25),
18+
( 4.0, 4.26, 4.0, 3.10, 4.0, 5.39, 19.0, 12.50),
19+
(12.0, 10.84, 12.0, 9.13, 12.0, 8.15, 8.0, 5.56),
20+
( 7.0, 4.82, 7.0, 7.26, 7.0, 6.42, 8.0, 7.91),
21+
( 5.0, 5.68, 5.0, 4.74, 5.0, 5.73, 8.0, 6.89))
22+
23+
object circles extends ColumnDataSource {
24+
val xi = column(anscombe_quartet(::, 0))
25+
val yi = column(anscombe_quartet(::, 1))
26+
val xii = column(anscombe_quartet(::, 2))
27+
val yii = column(anscombe_quartet(::, 3))
28+
val xiii = column(anscombe_quartet(::, 4))
29+
val yiii = column(anscombe_quartet(::, 5))
30+
val xiv = column(anscombe_quartet(::, 6))
31+
val yiv = column(anscombe_quartet(::, 7))
32+
}
33+
34+
object lines extends ColumnDataSource {
35+
val x = column(linspace(-0.5, 20.5, 10))
36+
val y = column(x.value*0.5 + 3.0)
37+
}
38+
39+
object lines1 extends ColumnDataSource {
40+
val x = column(linspace(-1.5, 20.5, 10))
41+
val y = column(x.value*0.7 + 1.0)
42+
}
43+
44+
val xdr = Range1d(-0.5, 20.5)
45+
val ydr = Range1d(-0.5, 20.5)
46+
47+
type Col = circles.Column[DenseVector, Double]
48+
49+
def make_plot(title: String, x_col: Col, y_col: Col) = {
50+
val fig = Figure(title, 400, 400)
51+
.x_range(xdr)
52+
.y_range(ydr)
53+
.border_fill_color(Color.White)
54+
.background_fill_color("#e9e0db")
55+
// fig.x_axis.axis_line_color()
56+
// fig.y_axis.axis_line_color()
57+
fig.line(lines)(_.x, _.y).line_color("#666699").line_width(2)
58+
fig.circle(x_col, y_col).size(12).fill_color("#cc6633").line_color("#cc6633").fill_alpha(50%%)
59+
fig
60+
}
61+
62+
val I = make_plot("I", circles.xi, circles.yi)
63+
val II = make_plot("II", circles.xii, circles.yii)
64+
val III = make_plot("III", circles.xiii, circles.yiii)
65+
val IV = make_plot("IV", circles.xiv, circles.yiv)
66+
67+
val grid = GridPlot((I, II),
68+
(III, IV)).width(800)
69+
70+
val html = grid.save("anscombe.html", config.resources)
71+
info(s"Wrote ${html.file}. Open ${html.url} in a web browser.")
72+
}

examples/src/test/scala/Examples.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class ExamplesSpec extends Specification with RunMatchers {
3939
"run Trail" in { models.Trail must run }
4040
"run TwinAxis" in { models.TwinAxis must run }
4141
}
42+
43+
"examples.plotting" should {
44+
"run Anscombe" in { plotting.Anscombe must run }
45+
}
4246
}
4347

4448
trait RunMatchers {

0 commit comments

Comments
 (0)