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

Function Example

plotter/general_example_test.go:16–66  ·  view source on GitHub ↗

Draw the plot logo.

()

Source from the content-addressed store, hash-verified

14
15// Draw the plot logo.
16func Example() {
17 p := plot.New()
18
19 plotter.DefaultLineStyle.Width = vg.Points(1)
20 plotter.DefaultGlyphStyle.Radius = vg.Points(3)
21
22 p.Y.Tick.Marker = plot.ConstantTicks([]plot.Tick{
23 {Value: 0, Label: "0"}, {Value: 0.25, Label: ""}, {Value: 0.5, Label: "0.5"}, {Value: 0.75, Label: ""}, {Value: 1, Label: "1"},
24 })
25 p.X.Tick.Marker = plot.ConstantTicks([]plot.Tick{
26 {Value: 0, Label: "0"}, {Value: 0.25, Label: ""}, {Value: 0.5, Label: "0.5"}, {Value: 0.75, Label: ""}, {Value: 1, Label: "1"},
27 })
28
29 pts := plotter.XYs{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 0.5, Y: 1}, {X: 0.5, Y: 0.6}, {X: 0, Y: 0.6}}
30 line, err := plotter.NewLine(pts)
31 if err != nil {
32 log.Panic(err)
33 }
34 scatter, err := plotter.NewScatter(pts)
35 if err != nil {
36 log.Panic(err)
37 }
38 p.Add(line, scatter)
39
40 pts = plotter.XYs{{X: 1, Y: 0}, {X: 0.75, Y: 0}, {X: 0.75, Y: 0.75}}
41 line, err = plotter.NewLine(pts)
42 if err != nil {
43 log.Panic(err)
44 }
45 scatter, err = plotter.NewScatter(pts)
46 if err != nil {
47 log.Panic(err)
48 }
49 p.Add(line, scatter)
50
51 pts = plotter.XYs{{X: 0.5, Y: 0.5}, {X: 1, Y: 0.5}}
52 line, err = plotter.NewLine(pts)
53 if err != nil {
54 log.Panic(err)
55 }
56 scatter, err = plotter.NewScatter(pts)
57 if err != nil {
58 log.Panic(err)
59 }
60 p.Add(line, scatter)
61
62 err = p.Save(100, 100, "testdata/plotLogo.png")
63 if err != nil {
64 log.Panic(err)
65 }
66}

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
PointsFunction · 0.92
ConstantTicksTypeAlias · 0.92
NewLineFunction · 0.92
NewScatterFunction · 0.92
SaveMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected