| 16 | ) |
| 17 | |
| 18 | func ExampleLine_stepLine() { |
| 19 | rnd := rand.New(rand.NewPCG(1, 1)) |
| 20 | |
| 21 | // randomPoints returns some random x, y points |
| 22 | // with some interesting kind of trend. |
| 23 | randomPoints := func(n int, x float64) plotter.XYs { |
| 24 | pts := make(plotter.XYs, n) |
| 25 | for i := range pts { |
| 26 | pts[i].X = float64(i) + x |
| 27 | pts[i].Y = 5. + 10*rnd.Float64() |
| 28 | } |
| 29 | return pts |
| 30 | } |
| 31 | |
| 32 | n := 4 |
| 33 | |
| 34 | p := plot.New() |
| 35 | p.Title.Text = "Step Example" |
| 36 | p.X.Label.Text = "X" |
| 37 | p.Y.Label.Text = "Y" |
| 38 | p.Add(plotter.NewGrid()) |
| 39 | |
| 40 | stepPre, err := plotter.NewLine(randomPoints(n, 0)) |
| 41 | if err != nil { |
| 42 | log.Panic(err) |
| 43 | } |
| 44 | stepPre.StepStyle = plotter.PreStep |
| 45 | stepPre.FillColor = color.RGBA{R: 196, G: 255, B: 196, A: 255} |
| 46 | |
| 47 | stepMid, err := plotter.NewLine(randomPoints(n, 3.5)) |
| 48 | if err != nil { |
| 49 | log.Panic(err) |
| 50 | } |
| 51 | stepMid.StepStyle = plotter.MidStep |
| 52 | stepMid.LineStyle = draw.LineStyle{Color: color.RGBA{R: 196, B: 128, A: 255}, Width: vg.Points(1)} |
| 53 | |
| 54 | stepMidFilled, err := plotter.NewLine(randomPoints(n, 7)) |
| 55 | if err != nil { |
| 56 | log.Panic(err) |
| 57 | } |
| 58 | stepMidFilled.StepStyle = plotter.MidStep |
| 59 | stepMidFilled.LineStyle = draw.LineStyle{Color: color.RGBA{R: 196, B: 128, A: 255}, Width: vg.Points(1)} |
| 60 | stepMidFilled.FillColor = color.RGBA{R: 255, G: 196, B: 196, A: 255} |
| 61 | |
| 62 | stepPost, err := plotter.NewLine(randomPoints(n, 10.5)) |
| 63 | if err != nil { |
| 64 | log.Panic(err) |
| 65 | } |
| 66 | stepPost.StepStyle = plotter.PostStep |
| 67 | stepPost.LineStyle.Width = 0 |
| 68 | stepPost.FillColor = color.RGBA{R: 196, G: 196, B: 255, A: 255} |
| 69 | |
| 70 | p.Add(stepPre, stepMid, stepMidFilled, stepPost) |
| 71 | p.Legend.Add("pre", stepPre) |
| 72 | p.Legend.Add("mid", stepMid) |
| 73 | p.Legend.Add("midFilled", stepMidFilled) |
| 74 | p.Legend.Add("post", stepPost) |
| 75 | p.Legend.Top = true |