NewErrorPoints returns a new ErrorPoints where each point in the ErrorPoints is given by evaluating the center function on the Xs and Ys for the corresponding set of XY values in the pts parameter. The XError and YError are computed likewise, using the err function. This function can be useful for
(f func([]float64) (c, l, h float64), pts ...plotter.XYer)
| 30 | // scatter points using a single point and error bars for |
| 31 | // each element of the scatter. |
| 32 | func NewErrorPoints(f func([]float64) (c, l, h float64), pts ...plotter.XYer) (*ErrorPoints, error) { |
| 33 | |
| 34 | c := &ErrorPoints{ |
| 35 | XYs: make(plotter.XYs, len(pts)), |
| 36 | XErrors: make(plotter.XErrors, len(pts)), |
| 37 | YErrors: make(plotter.YErrors, len(pts)), |
| 38 | } |
| 39 | |
| 40 | for i, xy := range pts { |
| 41 | xs := make([]float64, xy.Len()) |
| 42 | ys := make([]float64, xy.Len()) |
| 43 | for j := range xy.Len() { |
| 44 | xs[j], ys[j] = xy.XY(j) |
| 45 | if err := plotter.CheckFloats(xs[j], ys[j]); err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | } |
| 49 | c.XYs[i].X, c.XErrors[i].Low, c.XErrors[i].High = f(xs) |
| 50 | if err := plotter.CheckFloats(c.XYs[i].X, c.XErrors[i].Low, c.XErrors[i].High); err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | c.XYs[i].Y, c.YErrors[i].Low, c.YErrors[i].High = f(ys) |
| 54 | if err := plotter.CheckFloats(c.XYs[i].Y, c.YErrors[i].Low, c.YErrors[i].High); err != nil { |
| 55 | return nil, err |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return c, nil |
| 60 | } |
| 61 | |
| 62 | // MeanAndConf95 returns the mean |
| 63 | // and the magnitude of the 95% confidence |