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

Function AddScatters

plotutil/add.go:136–169  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

134// If an error occurs then none of the plotters are added
135// to the plot, and the error is returned.
136func 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

Callers 2

ExampleErrorPointsFunction · 0.92
Example_errpointsFunction · 0.92

Calls 4

NewScatterFunction · 0.92
ShapeFunction · 0.85
ColorFunction · 0.70
AddMethod · 0.45

Tested by 1

ExampleErrorPointsFunction · 0.74