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

Function Example_writerToCanvas

vg/example_test.go:152–189  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

150}
151
152func Example_writerToCanvas() {
153 p := plot.New()
154 p.Title.Text = "cos(x)"
155 p.X.Label.Text = "x"
156 p.Y.Label.Text = "f(x)"
157
158 p.X.Min = -2 * math.Pi
159 p.X.Max = +2 * math.Pi
160
161 fct := plotter.NewFunction(func(x float64) float64 {
162 return math.Cos(x)
163 })
164 fct.Color = color.RGBA{B: 255, A: 255}
165
166 p.Add(fct, plotter.NewGrid())
167
168 c := vgimg.PngCanvas{
169 Canvas: vgimg.New(10*vg.Centimeter, 5*vg.Centimeter),
170 }
171 p.Draw(draw.New(c))
172
173 // Save image.
174 f, err := os.Create("testdata/cosine.png")
175 if err != nil {
176 log.Fatalf("could not create output image file: %+v", err)
177 }
178 defer f.Close()
179
180 _, err = c.WriteTo(f)
181 if err != nil {
182 log.Fatalf("could not encode image to PNG: %+v", err)
183 }
184
185 err = f.Close()
186 if err != nil {
187 log.Fatalf("could not close output image file: %+v", err)
188 }
189}

Callers

nothing calls this directly

Calls 9

WriteToMethod · 0.95
NewFunction · 0.92
NewFunctionFunction · 0.92
NewGridFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
CloseMethod · 0.80
DrawMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected