NewHistogram returns a new histogram that represents the distribution of values using the given number of bins. Each y value is assumed to be the frequency count for the corresponding x. If the number of bins is non-positive than a reasonable default is used.
(xy XYer, n int)
| 52 | // If the number of bins is non-positive than |
| 53 | // a reasonable default is used. |
| 54 | func NewHistogram(xy XYer, n int) (*Histogram, error) { |
| 55 | if n <= 0 { |
| 56 | return nil, errors.New("Histogram with non-positive number of bins") |
| 57 | } |
| 58 | bins, width := binPoints(xy, n) |
| 59 | return &Histogram{ |
| 60 | Bins: bins, |
| 61 | Width: width, |
| 62 | FillColor: color.Gray{128}, |
| 63 | LineStyle: DefaultLineStyle, |
| 64 | }, nil |
| 65 | } |
| 66 | |
| 67 | // NewHist returns a new histogram, as in |
| 68 | // NewHistogram, except that it accepts a Valuer |