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

Function ExampleContour

plotter/contour_example_test.go:22–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20)
21
22func ExampleContour() {
23 rnd := rand.New(rand.NewPCG(1234, 1234))
24
25 const stddev = 2
26 data := make([]float64, 6400)
27 for i := range data {
28 r := float64(i/80) - 40
29 c := float64(i%80) - 40
30
31 data[i] = rnd.NormFloat64()*stddev + math.Hypot(r, c)
32 }
33
34 var (
35 grid = unitGrid{mat.NewDense(80, 80, data)}
36 levels = []float64{-1, 3, 7, 9, 13, 15, 19, 23, 27, 31}
37
38 c = plotter.NewContour(
39 grid,
40 levels,
41 palette.Rainbow(10, palette.Blue, palette.Red, 1, 1, 1),
42 )
43 )
44
45 p := plot.New()
46 p.Title.Text = "Contour"
47 p.X.Padding = 0
48 p.Y.Padding = 0
49 p.X.Max = 79.5
50 p.Y.Max = 79.5
51
52 p.Add(c)
53
54 err := p.Save(10*vg.Centimeter, 10*vg.Centimeter, "testdata/contour_"+runtime.GOARCH+".png")
55 if err != nil {
56 log.Fatalf("could not save plot: %+v", err)
57 }
58}
59
60type unitGrid struct{ mat.Matrix }
61

Callers

nothing calls this directly

Calls 5

NewContourFunction · 0.92
RainbowFunction · 0.92
NewFunction · 0.92
SaveMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected