-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtiledplot_example_test.go
108 lines (90 loc) · 2.15 KB
/
tiledplot_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright ©2016 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package hplot_test
import (
"fmt"
"image/color"
"log"
"math"
"math/rand/v2"
"go-hep.org/x/hep/hbook"
"go-hep.org/x/hep/hplot"
"gonum.org/v1/gonum/stat/distuv"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
)
// An example of making a tile-plot
func ExampleTiledPlot() {
tp := hplot.NewTiledPlot(draw.Tiles{Cols: 3, Rows: 2})
// Create a normal distribution.
dist := distuv.Normal{
Mu: 0,
Sigma: 1,
Src: rand.New(rand.NewPCG(0, 0)),
}
newHist := func(p *hplot.Plot) {
const npoints = 10000
hist := hbook.NewH1D(20, -4, +4)
for range npoints {
v := dist.Rand()
hist.Fill(v, 1)
}
h := hplot.NewH1D(hist)
p.Add(h)
}
for i := range tp.Tiles.Rows {
for j := range tp.Tiles.Cols {
p := tp.Plot(j, i)
p.X.Min = -5
p.X.Max = +5
newHist(p)
p.Title.Text = fmt.Sprintf("hist - (%02d, %02d)", j, i)
}
}
// remove plot at (1,0)
tp.Plots[1] = nil
err := tp.Save(15*vg.Centimeter, -1, "testdata/tiled_plot_histogram.png")
if err != nil {
log.Fatalf("error: %+v\n", err)
}
}
// An example of making aligned tile-plots
func ExampleTiledPlot_align() {
tp := hplot.NewTiledPlot(draw.Tiles{
Cols: 3, Rows: 3,
PadX: 20, PadY: 20,
})
tp.Align = true
points := func(i, j int) []hbook.Point2D {
n := i*tp.Tiles.Cols + j + 1
i += 1
j = int(math.Pow(10, float64(n)))
var pts []hbook.Point2D
for ii := range 10 {
pts = append(pts, hbook.Point2D{
X: float64(i + ii),
Y: float64(j + ii + 1),
})
}
return pts
}
for i := range tp.Tiles.Rows {
for j := range tp.Tiles.Cols {
p := tp.Plot(j, i)
p.X.Min = -5
p.X.Max = +5
s := hplot.NewS2D(hbook.NewS2D(points(i, j)...))
s.GlyphStyle.Color = color.RGBA{R: 255, A: 255}
s.GlyphStyle.Radius = vg.Points(4)
p.Add(s)
p.Title.Text = fmt.Sprintf("hist - (%02d, %02d)", j, i)
}
}
// remove plot at (1,1)
tp.Plots[4] = nil
err := tp.Save(15*vg.Centimeter, -1, "testdata/tiled_plot_aligned_histogram.png")
if err != nil {
log.Fatalf("error: %+v\n", err)
}
}