MCPcopy Create free account
hub / github.com/darjun/go-daily-lib / main

Function main

plot/function/main.go:13–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func main() {
14 p, err := plot.New()
15 if err != nil {
16 log.Fatal(err)
17 }
18 p.Title.Text = "Functions"
19 p.X.Label.Text = "X"
20 p.Y.Label.Text = "Y"
21
22 square := plotter.NewFunction(func(x float64) float64 { return x * x })
23 square.Color = plotutil.Color(0)
24
25 sqrt := plotter.NewFunction(func(x float64) float64 { return 10 * math.Sqrt(x) })
26 sqrt.Dashes = []vg.Length{vg.Points(1), vg.Points(2)}
27 sqrt.Width = vg.Points(1)
28 sqrt.Color = plotutil.Color(1)
29
30 exp := plotter.NewFunction(func(x float64) float64 { return math.Pow(2, x) })
31 exp.Dashes = []vg.Length{vg.Points(2), vg.Points(3)}
32 exp.Width = vg.Points(2)
33 exp.Color = plotutil.Color(2)
34
35 sin := plotter.NewFunction(func(x float64) float64 { return 10*math.Sin(x) + 50 })
36 sin.Dashes = []vg.Length{vg.Points(3), vg.Points(4)}
37 sin.Width = vg.Points(3)
38 sin.Color = plotutil.Color(3)
39
40 p.Add(square, sqrt, exp, sin)
41 p.Legend.Add("x^2", square)
42 p.Legend.Add("10*sqrt(x)", sqrt)
43 p.Legend.Add("2^x", exp)
44 p.Legend.Add("10*sin(x)+50", sin)
45 p.Legend.ThumbnailWidth = 0.5 * vg.Inch
46
47 p.X.Min = 0
48 p.X.Max = 10
49 p.Y.Min = 0
50 p.Y.Max = 100
51
52 if err = p.Save(4*vg.Inch, 4*vg.Inch, "functions.png"); err != nil {
53 log.Fatal(err)
54 }
55}

Callers

nothing calls this directly

Calls 1

AddMethod · 0.45

Tested by

no test coverage detected