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

Function AddStackedAreaPlots

plotutil/add.go:39–84  ·  view source on GitHub ↗

AddStackedAreaPlots adds stacked area plot plotters to a plot. The variadic arguments must be either strings or plotter.Valuers. Each valuer adds a stacked area plot to the plot below the stacked area plots added before it. If a plotter.Valuer is immediately preceeded by a string then the string v

(plt *plot.Plot, xs plotter.Valuer, vs ...any)

Source from the content-addressed store, hash-verified

37// If an error occurs then none of the plotters are added
38// to the plot, and the error is returned.
39func AddStackedAreaPlots(plt *plot.Plot, xs plotter.Valuer, vs ...any) error {
40 var ps []plot.Plotter
41 var names []item
42 name := ""
43 var i int
44
45 for _, v := range vs {
46 switch t := v.(type) {
47 case string:
48 name = t
49
50 case plotter.Valuer:
51 if xs.Len() != t.Len() {
52 return errors.New("X/Y length mismatch")
53 }
54
55 // Make a line plotter and set its style.
56 l, err := plotter.NewLine(combineXYs{xs: xs, ys: t})
57 if err != nil {
58 return err
59 }
60
61 l.LineStyle.Width = vg.Points(0)
62 color := Color(i)
63 i++
64 l.FillColor = color
65
66 ps = append(ps, l)
67
68 if name != "" {
69 names = append(names, item{name: name, value: l})
70 name = ""
71 }
72
73 default:
74 panic(fmt.Sprintf("plotutil: AddStackedAreaPlots handles strings and plotter.Valuers, got %T", t))
75 }
76 }
77
78 plt.Add(ps...)
79 for _, v := range names {
80 plt.Legend.Add(v.name, v.value)
81 }
82
83 return nil
84}
85
86// AddBoxPlots adds box plot plotters to a plot and
87// sets the X axis of the plot to be nominal.

Callers 1

Example_stackedAreaChartFunction · 0.92

Calls 5

NewLineFunction · 0.92
PointsFunction · 0.92
ColorFunction · 0.70
LenMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…