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

Function ExampleFunction

plotter/functions_example_test.go:18–52  ·  view source on GitHub ↗

ExampleFunction draws some functions.

()

Source from the content-addressed store, hash-verified

16
17// ExampleFunction draws some functions.
18func ExampleFunction() {
19 quad := plotter.NewFunction(func(x float64) float64 { return x * x })
20 quad.Color = color.RGBA{B: 255, A: 255}
21
22 exp := plotter.NewFunction(func(x float64) float64 { return math.Pow(2, x) })
23 exp.Dashes = []vg.Length{vg.Points(2), vg.Points(2)}
24 exp.Width = vg.Points(2)
25 exp.Color = color.RGBA{G: 255, A: 255}
26
27 sin := plotter.NewFunction(func(x float64) float64 { return 10*math.Sin(x) + 50 })
28 sin.Dashes = []vg.Length{vg.Points(4), vg.Points(5)}
29 sin.Width = vg.Points(4)
30 sin.Color = color.RGBA{R: 255, A: 255}
31
32 p := plot.New()
33 p.Title.Text = "Functions"
34 p.X.Label.Text = "X"
35 p.Y.Label.Text = "Y"
36
37 p.Add(quad, exp, sin)
38 p.Legend.Add("x^2", quad)
39 p.Legend.Add("2^x", exp)
40 p.Legend.Add("10*sin(x)+50", sin)
41 p.Legend.ThumbnailWidth = 0.5 * vg.Inch
42
43 p.X.Min = 0
44 p.X.Max = 10
45 p.Y.Min = 0
46 p.Y.Max = 100
47
48 err := p.Save(200, 200, "testdata/functions.png")
49 if err != nil {
50 log.Panic(err)
51 }
52}

Callers

nothing calls this directly

Calls 5

NewFunctionFunction · 0.92
PointsFunction · 0.92
NewFunction · 0.92
SaveMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected