// Example_errBars draws points and error bars. func Example_errBars() *plot.Plot { type errPoints struct { plotter.XYs plotter.YErrors plotter.XErrors } rand.Seed(int64(0)) n := 15 data := errPoints{ plotter.XYs: randomPoints(n), plotter.YErrors: plotter.YErrors(randomError(n)), plotter.XErrors: plotter.XErrors(randomError(n)), } p, err := plot.New() if err != nil { panic(err) } scatter := plotter.NewScatter(data) scatter.Shape = plot.CrossGlyph{} p.Add(scatter, plotter.NewXErrorBars(data), plotter.NewYErrorBars(data)) p.Add(plotter.NewGlyphBoxes()) return p }
// AddErrorBars adds XErrorBars and YErrorBars // to a plot. The variadic arguments must be // of type plotter.XYer, and must be either a // plotter.XErrorer, plotter.YErrorer, or both. // Each errorer is added to the plot the color from // the Colors function corresponding to its position // in the argument list. func AddErrorBars(plt *plot.Plot, vs ...interface{}) { for i, v := range vs { added := false if xerr, ok := v.(interface { plotter.XYer plotter.XErrorer }); ok { e := plotter.NewXErrorBars(xerr) e.Color = Color(i) plt.Add(e) added = true } if yerr, ok := v.(interface { plotter.XYer plotter.YErrorer }); ok { e := plotter.NewYErrorBars(yerr) e.Color = Color(i) plt.Add(e) added = true } if added { continue } panic(fmt.Sprintf("AddErrorBars expects plotter.XErrorer or plotter.YErrorer, got %T", v)) } }
// AddYErrorBars adds YErrorBars to a plot. // The variadic arguments must be // of type plotter.XYer, and plotter.YErrorer. // Each errorer is added to the plot the color from // the Colors function corresponding to its position // in the argument list. func AddYErrorBars(plt *plot.Plot, es ...interface { plotter.XYer plotter.YErrorer }) { for i, e := range es { bars := plotter.NewYErrorBars(e) bars.Color = Color(i) plt.Add(bars) } }