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

Function Example_inMemoryCanvas

vg/example_test.go:115–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

113}
114
115func Example_inMemoryCanvas() {
116 p := plot.New()
117 p.Title.Text = "sin(x)"
118 p.X.Label.Text = "x"
119 p.Y.Label.Text = "f(x)"
120
121 p.X.Min = -2 * math.Pi
122 p.X.Max = +2 * math.Pi
123
124 fct := plotter.NewFunction(func(x float64) float64 {
125 return math.Sin(x)
126 })
127 fct.Color = color.RGBA{R: 255, A: 255}
128
129 p.Add(fct, plotter.NewGrid())
130
131 c := vgimg.New(10*vg.Centimeter, 5*vg.Centimeter)
132 p.Draw(draw.New(c))
133
134 // Save image.
135 f, err := os.Create("testdata/sine.png")
136 if err != nil {
137 log.Fatalf("could not create output image file: %+v", err)
138 }
139 defer f.Close()
140
141 err = png.Encode(f, c.Image())
142 if err != nil {
143 log.Fatalf("could not encode image to PNG: %+v", err)
144 }
145
146 err = f.Close()
147 if err != nil {
148 log.Fatalf("could not close output image file: %+v", err)
149 }
150}
151
152func Example_writerToCanvas() {
153 p := plot.New()

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
NewFunctionFunction · 0.92
NewGridFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
CloseMethod · 0.80
ImageMethod · 0.80
DrawMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected