AddLinePoints adds Line and Scatter plotters to a plot. The variadic arguments must be either strings or plotter.XYers. Each plotter.XYer is added to the plot using the next color, dashes, and glyph shape via the Color, Dashes, and Shape functions. If a plotter.XYer is immediately preceeded by a s
(plt *plot.Plot, vs ...any)
| 237 | // If an error occurs then none of the plotters are added |
| 238 | // to the plot, and the error is returned. |
| 239 | func AddLinePoints(plt *plot.Plot, vs ...any) error { |
| 240 | var ps []plot.Plotter |
| 241 | type item struct { |
| 242 | name string |
| 243 | value [2]plot.Thumbnailer |
| 244 | } |
| 245 | var items []item |
| 246 | name := "" |
| 247 | var i int |
| 248 | for _, v := range vs { |
| 249 | switch t := v.(type) { |
| 250 | case string: |
| 251 | name = t |
| 252 | |
| 253 | case plotter.XYer: |
| 254 | l, s, err := plotter.NewLinePoints(t) |
| 255 | if err != nil { |
| 256 | return err |
| 257 | } |
| 258 | l.Color = Color(i) |
| 259 | l.Dashes = Dashes(i) |
| 260 | s.Color = Color(i) |
| 261 | s.Shape = Shape(i) |
| 262 | i++ |
| 263 | ps = append(ps, l, s) |
| 264 | if name != "" { |
| 265 | items = append(items, item{name: name, value: [2]plot.Thumbnailer{l, s}}) |
| 266 | name = "" |
| 267 | } |
| 268 | |
| 269 | default: |
| 270 | panic(fmt.Sprintf("plotutil: AddLinePoints handles strings and plotter.XYers, got %T", t)) |
| 271 | } |
| 272 | } |
| 273 | plt.Add(ps...) |
| 274 | for _, item := range items { |
| 275 | v := item.value[:] |
| 276 | plt.Legend.Add(item.name, v[0], v[1]) |
| 277 | } |
| 278 | return nil |
| 279 | } |
| 280 | |
| 281 | // AddErrorBars adds XErrorBars and YErrorBars |
| 282 | // to a plot. The variadic arguments must be |