Skip to content

Commit b9ab8b8

Browse files
committed
Add plot examples
1 parent dfbbfae commit b9ab8b8

8 files changed

+88
-0
lines changed

examples/plot_bar_category.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import geoscript.layer.Shapefile
2+
import geoscript.plot.Bar
3+
4+
def layer = new Shapefile("states.shp")
5+
def data = [:] as TreeMap
6+
layer.cursor.each{f ->
7+
def letter = f['STATE_NAME'][0]
8+
if (!data.containsKey(letter)) {
9+
data[letter] = 0
10+
}
11+
data[letter] = data[letter] + 1
12+
}
13+
14+
Bar.category(data).show()

examples/plot_bar_xy.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import geoscript.layer.Shapefile
2+
import geoscript.plot.Bar
3+
4+
def layer = new Shapefile("states.shp")
5+
def data = layer.cursor.collect{f ->
6+
[
7+
f['PERSONS'],
8+
f['EMPLOYED']
9+
]
10+
}
11+
12+
Bar.xy(data, title: "# People vs. Employed", yLabel: "Employed", xLabel: "Persons", legend: false).show()

examples/plot_box.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import geoscript.plot.Box
2+
3+
Box.box(["A":[1,10,20],"B":[45,39,10],"C":[2,4,9],"D":[14,15,19]]).show()
4+

examples/plot_curve.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import geoscript.layer.Shapefile
2+
import geoscript.plot.Curve
3+
4+
def layer = new Shapefile("states.shp")
5+
def data = layer.cursor.collect{f ->
6+
[
7+
f['PERSONS'],
8+
f['EMPLOYED']
9+
]
10+
}
11+
12+
Curve.curve(data, title: "# People vs. Employed", yLabel: "Employed", xLabel: "Persons", legend: false).show()

examples/plot_pie.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import geoscript.layer.*
2+
import geoscript.plot.Pie
3+
4+
Layer layer = new Shapefile("states.shp")
5+
Map data = [:] as TreeMap
6+
layer.cursor.each {f ->
7+
String region = f['SUB_REGION']
8+
if (!data.containsKey(region)) {
9+
data[region] = 0
10+
}
11+
data[region] = data[region] + 1
12+
}
13+
14+
Pie.pie(data, title: "States per Region").show()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import geoscript.layer.Shapefile
2+
import geoscript.plot.Regression
3+
4+
def layer = new Shapefile("states.shp")
5+
def data = layer.cursor.collect{f ->
6+
[
7+
f['PERSONS'],
8+
f['EMPLOYED']
9+
]
10+
}
11+
12+
Regression.linear(data, yLabel: "Employed", xLabel: "Persons", legend: false).show()

examples/plot_regression_power.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import geoscript.layer.Shapefile
2+
import geoscript.plot.Regression
3+
4+
def layer = new Shapefile("states.shp")
5+
def data = layer.cursor.collect{f ->
6+
[
7+
f['PERSONS'],
8+
f['EMPLOYED']
9+
]
10+
}
11+
12+
Regression.power(data, yLabel: "Employed", xLabel: "Persons", legend: false).show()

examples/plot_scatter.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import geoscript.geom.*
2+
import geoscript.plot.Scatter
3+
4+
def points = Geometry.createRandomPoints(new Bounds(0,0,100,100).geometry, 100)
5+
List data = points.geometries.collect{pt ->
6+
[pt.x,pt.y]
7+
}
8+
Scatter.scatterplot(data).show()

0 commit comments

Comments
 (0)