-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.go
58 lines (48 loc) · 1.15 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"image/color"
"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/vg"
)
var (
palette = color.Palette{
color.RGBA{R: 255, G: 0, B: 0},
color.RGBA{R: 0, G: 255, B: 0},
color.RGBA{R: 0, G: 0, B: 255},
color.RGBA{R: 0, G: 255, B: 255},
color.RGBA{R: 255, G: 0, B: 255},
color.RGBA{R: 255, G: 255, B: 0},
color.RGBA{R: 127, G: 205, B: 187},
color.RGBA{R: 117, G: 107, B: 177},
color.RGBA{R: 217, G: 95, B: 14},
color.RGBA{R: 0, G: 0, B: 0},
}
)
func plotLines(lines []plotter.XYs, legends []string, title, xlabel, ylabel, filepath string) {
if len(lines) > len(palette) {
panic("not enough colors !")
}
p, err := plot.New()
if err != nil {
panic(err)
}
p.Title.Text = title
p.X.Label.Text = xlabel
p.Y.Label.Text = ylabel
p.Add(plotter.NewGrid())
for i, line := range lines {
li, po, err := plotter.NewLinePoints(line)
if err != nil {
panic(err)
}
li.LineStyle.Width = vg.Points(1)
li.Color = palette[i]
po.Color = palette[i]
p.Add(li, po)
p.Legend.Add(legends[i], li, po)
}
if err := p.Save(40*vg.Centimeter, 40*vg.Centimeter, filepath); err != nil {
panic(err)
}
}