MCPcopy Index your code
hub / github.com/gonum/plot / AddLines

Function AddLines

plotutil/add.go:183–226  ·  view source on GitHub ↗

AddLines adds Line plotters to a plot. The variadic arguments must be a string or one of a plotting type, plotter.XYers or *plotter.Function. Each plotting type is added to the plot using the next color and dashes shape via the Color and Dashes functions. If a plotting type is immediately preceeded

(plt *plot.Plot, vs ...any)

Source from the content-addressed store, hash-verified

181// If an error occurs then none of the plotters are added
182// to the plot, and the error is returned.
183func AddLines(plt *plot.Plot, vs ...any) error {
184 var ps []plot.Plotter
185 var items []item
186 name := ""
187 var i int
188 for _, v := range vs {
189 switch t := v.(type) {
190 case string:
191 name = t
192
193 case plotter.XYer:
194 l, err := plotter.NewLine(t)
195 if err != nil {
196 return err
197 }
198 l.Color = Color(i)
199 l.Dashes = Dashes(i)
200 i++
201 ps = append(ps, l)
202 if name != "" {
203 items = append(items, item{name: name, value: l})
204 name = ""
205 }
206
207 case *plotter.Function:
208 t.Color = Color(i)
209 t.Dashes = Dashes(i)
210 i++
211 ps = append(ps, t)
212 if name != "" {
213 items = append(items, item{name: name, value: t})
214 name = ""
215 }
216
217 default:
218 panic(fmt.Sprintf("plotutil: AddLines handles strings, plotter.XYers and *plotter.Function, got %T", t))
219 }
220 }
221 plt.Add(ps...)
222 for _, v := range items {
223 plt.Legend.Add(v.name, v.value)
224 }
225 return nil
226}
227
228// AddLinePoints adds Line and Scatter plotters to a
229// plot. The variadic arguments must be either strings

Callers

nothing calls this directly

Calls 4

NewLineFunction · 0.92
DashesFunction · 0.85
ColorFunction · 0.70
AddMethod · 0.45

Tested by

no test coverage detected