AddScatters adds 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, and glyph shape via the Color and Shape functions. If a plotter.XYer is immediately preceeded by a string then a legend entry is
(plt *plot.Plot, vs ...any)
| 134 | // If an error occurs then none of the plotters are added |
| 135 | // to the plot, and the error is returned. |
| 136 | func AddScatters(plt *plot.Plot, vs ...any) error { |
| 137 | var ps []plot.Plotter |
| 138 | var items []item |
| 139 | name := "" |
| 140 | var i int |
| 141 | for _, v := range vs { |
| 142 | switch t := v.(type) { |
| 143 | case string: |
| 144 | name = t |
| 145 | |
| 146 | case plotter.XYer: |
| 147 | s, err := plotter.NewScatter(t) |
| 148 | if err != nil { |
| 149 | return err |
| 150 | } |
| 151 | s.Color = Color(i) |
| 152 | s.Shape = Shape(i) |
| 153 | i++ |
| 154 | ps = append(ps, s) |
| 155 | if name != "" { |
| 156 | items = append(items, item{name: name, value: s}) |
| 157 | name = "" |
| 158 | } |
| 159 | |
| 160 | default: |
| 161 | panic(fmt.Sprintf("plotutil: AddScatters handles strings and plotter.XYers, got %T", t)) |
| 162 | } |
| 163 | } |
| 164 | plt.Add(ps...) |
| 165 | for _, v := range items { |
| 166 | plt.Legend.Add(v.name, v.value) |
| 167 | } |
| 168 | return nil |
| 169 | } |
| 170 | |
| 171 | // AddLines adds Line plotters to a plot. |
| 172 | // The variadic arguments must be a string |