| 15 | ) |
| 16 | |
| 17 | func ExampleLine_filledLine() { |
| 18 | rnd := rand.New(rand.NewPCG(1, 1)) |
| 19 | |
| 20 | // randomPoints returns some random x, y points |
| 21 | // with some interesting kind of trend. |
| 22 | randomPoints := func(n int, x float64) plotter.XYs { |
| 23 | pts := make(plotter.XYs, n) |
| 24 | for i := range pts { |
| 25 | if i == 0 { |
| 26 | pts[i].X = x + rnd.Float64() |
| 27 | } else { |
| 28 | pts[i].X = pts[i-1].X + 0.5 + rnd.Float64() |
| 29 | } |
| 30 | pts[i].Y = -5. + 10*rnd.Float64() |
| 31 | } |
| 32 | return pts |
| 33 | } |
| 34 | |
| 35 | p := plot.New() |
| 36 | p.Title.Text = "Filled Line Example" |
| 37 | p.X.Label.Text = "X" |
| 38 | p.Y.Label.Text = "Y" |
| 39 | p.Add(plotter.NewGrid()) |
| 40 | |
| 41 | filled, err := plotter.NewLine(randomPoints(4, 0)) |
| 42 | if err != nil { |
| 43 | log.Panic(err) |
| 44 | } |
| 45 | filled.FillColor = color.RGBA{R: 196, G: 255, B: 196, A: 255} |
| 46 | |
| 47 | p.Add(filled) |
| 48 | |
| 49 | err = p.Save(200, 200, "testdata/filledLine_"+runtime.GOARCH+".png") |
| 50 | if err != nil { |
| 51 | log.Panic(err) |
| 52 | } |
| 53 | } |