()
| 16 | ) |
| 17 | |
| 18 | func ExampleBoxPlot() { |
| 19 | rnd := rand.New(rand.NewPCG(1, 1)) |
| 20 | |
| 21 | // Create the sample data. |
| 22 | const n = 100 |
| 23 | uniform := make(plotter.ValueLabels, n) |
| 24 | normal := make(plotter.ValueLabels, n) |
| 25 | expon := make(plotter.ValueLabels, n) |
| 26 | for i := range n { |
| 27 | uniform[i].Value = rnd.Float64() |
| 28 | uniform[i].Label = fmt.Sprintf("%4.4f", uniform[i].Value) |
| 29 | normal[i].Value = rnd.NormFloat64() |
| 30 | normal[i].Label = fmt.Sprintf("%4.4f", normal[i].Value) |
| 31 | expon[i].Value = rnd.ExpFloat64() |
| 32 | expon[i].Label = fmt.Sprintf("%4.4f", expon[i].Value) |
| 33 | } |
| 34 | |
| 35 | // Make boxes for our data and add them to the plot. |
| 36 | uniBox, err := plotter.NewBoxPlot(vg.Points(20), 0, uniform) |
| 37 | if err != nil { |
| 38 | log.Panic(err) |
| 39 | } |
| 40 | uniBox.FillColor = color.RGBA{127, 188, 165, 1} |
| 41 | normBox, err := plotter.NewBoxPlot(vg.Points(20), 1, normal) |
| 42 | if err != nil { |
| 43 | log.Panic(err) |
| 44 | } |
| 45 | normBox.FillColor = color.RGBA{127, 188, 165, 1} |
| 46 | expBox, err := plotter.NewBoxPlot(vg.Points(20), 2, expon) |
| 47 | if err != nil { |
| 48 | log.Panic(err) |
| 49 | } |
| 50 | expBox.FillColor = color.RGBA{127, 188, 165, 1} |
| 51 | |
| 52 | // Make a vertical box plot. |
| 53 | uniLabels, err := uniBox.OutsideLabels(uniform) |
| 54 | if err != nil { |
| 55 | log.Panic(err) |
| 56 | } |
| 57 | normLabels, err := normBox.OutsideLabels(normal) |
| 58 | if err != nil { |
| 59 | log.Panic(err) |
| 60 | } |
| 61 | expLabels, err := expBox.OutsideLabels(expon) |
| 62 | if err != nil { |
| 63 | log.Panic(err) |
| 64 | } |
| 65 | |
| 66 | p1 := plot.New() |
| 67 | p1.Title.Text = "Vertical Box Plot" |
| 68 | p1.Y.Label.Text = "plotter.Values" |
| 69 | p1.Y.Max = 6 |
| 70 | p1.Add(uniBox, uniLabels, normBox, normLabels, expBox, expLabels) |
| 71 | |
| 72 | // Set the X axis of the plot to nominal with |
| 73 | // the given names for x=0, x=1 and x=2. |
| 74 | p1.NominalX("Uniform\nDistribution", "Normal\nDistribution", |
| 75 | "Exponential\nDistribution") |
nothing calls this directly
no test coverage detected