// AddBoxPlots adds box plot plotters to a plot and // sets the X axis of the plot to be nominal. // The variadic arguments must be either strings // or plotter.Valuers. Each valuer adds a box plot // to the plot at the X location corresponding to // the number of box plots added before it. If a // plotter.Valuer is immediately preceeded by a // string then the string value is used to label the // tick mark for the box plot's X location. // // If an error occurs then none of the plotters are added // to the plot, and the error is returned. func AddBoxPlots(plt *plot.Plot, width vg.Length, vs ...interface{}) error { var ps []plot.Plotter var names []string name := "" for _, v := range vs { switch t := v.(type) { case string: name = t case plotter.Valuer: b, err := plotter.NewBoxPlot(width, float64(len(names)), t) if err != nil { return err } ps = append(ps, b) names = append(names, name) name = "" default: panic(fmt.Sprintf("AddScatters handles strings and plotter.XYers, got %T", t)) } } plt.Add(ps...) plt.NominalX(names...) return nil }