|
@@ -0,0 +1,77 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "image/color"
|
|
|
+ "log"
|
|
|
+ "math"
|
|
|
+ "math/rand"
|
|
|
+
|
|
|
+ "gonum.org/v1/plot"
|
|
|
+ "gonum.org/v1/plot/plotter"
|
|
|
+ "gonum.org/v1/plot/vg"
|
|
|
+ "gonum.org/v1/plot/vg/draw"
|
|
|
+)
|
|
|
+
|
|
|
+func main() {
|
|
|
+ rand.Seed(103)
|
|
|
+ randsinpts := func(n int, maxt float64) plotter.XYs {
|
|
|
+ pts := make(plotter.XYs, n)
|
|
|
+ for idx := range pts {
|
|
|
+ t := rand.Float64() * maxt
|
|
|
+ pts[idx].X = t
|
|
|
+ pts[idx].Y = math.Sin(t)
|
|
|
+ }
|
|
|
+ return pts
|
|
|
+ }
|
|
|
+
|
|
|
+ sinn := func(n int) plotter.XYs {
|
|
|
+ pts := make(plotter.XYs, n)
|
|
|
+ for idx := range pts {
|
|
|
+ t := float64(idx) * 0.001
|
|
|
+ pts[idx].X = t
|
|
|
+ pts[idx].Y = math.Sin(t)
|
|
|
+ }
|
|
|
+ return pts
|
|
|
+ }
|
|
|
+
|
|
|
+ n := 10000
|
|
|
+ data := sinn(n)
|
|
|
+
|
|
|
+ p, err := plot.New()
|
|
|
+ if err != nil {
|
|
|
+ log.Panic(err)
|
|
|
+ }
|
|
|
+ p.Title.Text = "Sine stuff"
|
|
|
+
|
|
|
+ p.X.Label.Text = "time (s)"
|
|
|
+ p.X.Max = 10
|
|
|
+ p.X.Min = 0
|
|
|
+
|
|
|
+ p.Y.Label.Text = "w/e"
|
|
|
+ p.Y.Max = 1
|
|
|
+ p.Y.Min = -1
|
|
|
+
|
|
|
+ p.Add(plotter.NewGrid())
|
|
|
+
|
|
|
+ line, err := plotter.NewLine(data)
|
|
|
+ if err != nil {
|
|
|
+ log.Panic(err)
|
|
|
+ }
|
|
|
+ line.Color = color.RGBA{B: 255, A: 255}
|
|
|
+ line.Width = vg.Millimeter / 2
|
|
|
+
|
|
|
+ randpts := randsinpts(3, data[len(data)-1].X)
|
|
|
+ points, err := plotter.NewScatter(randpts)
|
|
|
+ if err != nil {
|
|
|
+ log.Panic(err)
|
|
|
+ }
|
|
|
+ points.Shape = draw.CircleGlyph{}
|
|
|
+ points.Color = color.RGBA{R: 255, A: 255}
|
|
|
+
|
|
|
+ p.Add(line, points)
|
|
|
+
|
|
|
+ err = p.Save(10*vg.Centimeter, 5*vg.Centimeter, "plot.png")
|
|
|
+ if err != nil {
|
|
|
+ log.Panic(err)
|
|
|
+ }
|
|
|
+}
|