NewYErrorBars returns a new YErrorBars plotter, or an error on failure. The error values from the YErrorer interface are interpreted as relative to the corresponding Y value. The errors for a given Y value are computed by taking the absolute value of the error returned by the YErrorer and subtractin
(yerrs interface {
XYer
YErrorer
})
| 38 | // by taking the absolute value of the error returned by the YErrorer |
| 39 | // and subtracting the first and adding the second to the Y value. |
| 40 | func NewYErrorBars(yerrs interface { |
| 41 | XYer |
| 42 | YErrorer |
| 43 | }) (*YErrorBars, error) { |
| 44 | |
| 45 | errors := make(YErrors, yerrs.Len()) |
| 46 | for i := range errors { |
| 47 | errors[i].Low, errors[i].High = yerrs.YError(i) |
| 48 | if err := CheckFloats(errors[i].Low, errors[i].High); err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | } |
| 52 | xys, err := CopyXYs(yerrs) |
| 53 | if err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | |
| 57 | return &YErrorBars{ |
| 58 | XYs: xys, |
| 59 | YErrors: errors, |
| 60 | LineStyle: DefaultLineStyle, |
| 61 | CapWidth: DefaultCapWidth, |
| 62 | }, nil |
| 63 | } |
| 64 | |
| 65 | // Plot implements the Plotter interface, drawing labels. |
| 66 | func (e *YErrorBars) Plot(c draw.Canvas, p *plot.Plot) { |