-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.go
40 lines (32 loc) · 751 Bytes
/
plot.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
package changetest
import (
"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/plotutil"
"gonum.org/v1/plot/vg"
"github.com/mmcloughlin/goperf/app/trace"
)
// PlotSeries generates a plot for debugging purposes.
func PlotSeries(filename, title string, s trace.Series) error {
p, err := plot.New()
if err != nil {
return err
}
p.Title.Text = title
p.X.Label.Text = "commit index"
p.Y.Label.Text = "value"
pts := make(plotter.XYs, len(s))
for i, v := range s {
pts[i].X = float64(v.CommitIndex)
pts[i].Y = v.Value
}
err = plotutil.AddLinePoints(p, "series", pts)
if err != nil {
return err
}
// Save the plot.
if err := p.Save(6*vg.Inch, 4*vg.Inch, filename); err != nil {
return err
}
return nil
}