MCPcopy Index your code
hub / github.com/gonum/plot / ExampleErrors

Function ExampleErrors

plotter/errbars_example_test.go:17–76  ·  view source on GitHub ↗

ExampleErrors draws points and error bars.

()

Source from the content-addressed store, hash-verified

15
16// ExampleErrors draws points and error bars.
17func ExampleErrors() {
18 rnd := rand.New(rand.NewPCG(1, 1))
19
20 randomError := func(n int) plotter.Errors {
21 err := make(plotter.Errors, n)
22 for i := range err {
23 err[i].Low = rnd.Float64()
24 err[i].High = rnd.Float64()
25 }
26 return err
27 }
28 // randomPoints returns some random x, y points
29 // with some interesting kind of trend.
30 randomPoints := func(n int) plotter.XYs {
31 pts := make(plotter.XYs, n)
32 for i := range pts {
33 if i == 0 {
34 pts[i].X = rnd.Float64()
35 } else {
36 pts[i].X = pts[i-1].X + rnd.Float64()
37 }
38 pts[i].Y = pts[i].X + 10*rnd.Float64()
39 }
40 return pts
41 }
42
43 type errPoints struct {
44 plotter.XYs
45 plotter.YErrors
46 plotter.XErrors
47 }
48
49 n := 15
50 data := errPoints{
51 XYs: randomPoints(n),
52 YErrors: plotter.YErrors(randomError(n)),
53 XErrors: plotter.XErrors(randomError(n)),
54 }
55
56 p := plot.New()
57 scatter, err := plotter.NewScatter(data)
58 if err != nil {
59 log.Panic(err)
60 }
61 scatter.Shape = draw.CrossGlyph{}
62 xerrs, err := plotter.NewXErrorBars(data)
63 if err != nil {
64 log.Panic(err)
65 }
66 yerrs, err := plotter.NewYErrorBars(data)
67 if err != nil {
68 log.Panic(err)
69 }
70 p.Add(scatter, xerrs, yerrs)
71
72 err = p.Save(200, 200, "testdata/errorBars.png")
73 if err != nil {
74 log.Panic(err)

Callers

nothing calls this directly

Calls 9

YErrorsTypeAlias · 0.92
XErrorsTypeAlias · 0.92
NewFunction · 0.92
NewScatterFunction · 0.92
NewXErrorBarsFunction · 0.92
NewYErrorBarsFunction · 0.92
randomPointsFunction · 0.85
SaveMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected