MCPcopy Create free account
hub / github.com/gonum/plot / Example_multipage

Function Example_multipage

vg/vgpdf/vgpdf_example_test.go:58–99  ·  view source on GitHub ↗

Example_multipage shows how one can create a PDF with multiple pages.

()

Source from the content-addressed store, hash-verified

56
57// Example_multipage shows how one can create a PDF with multiple pages.
58func Example_multipage() {
59 c := vgpdf.New(5*vg.Centimeter, 5*vg.Centimeter)
60
61 for i, col := range []color.RGBA{{B: 255, A: 255}, {R: 255, A: 255}} {
62 if i > 0 {
63 // Add a new page.
64 c.NextPage()
65 }
66
67 p := plot.New()
68
69 pts := plotter.XYs{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 0}, {X: 1, Y: 1}}
70 line, err := plotter.NewLine(pts)
71 if err != nil {
72 log.Fatalf("could not create line: %v", err)
73 }
74 line.Color = col
75 p.Add(line)
76 p.Title.Text = fmt.Sprintf("Plot %d", i+1)
77 p.X.Label.Text = "X axis"
78 p.Y.Label.Text = "Y axis"
79
80 // Write plot to page.
81 p.Draw(draw.New(c))
82 }
83
84 f, err := os.Create("testdata/multipage.pdf")
85 if err != nil {
86 log.Fatal(err)
87 }
88 defer f.Close()
89
90 _, err = c.WriteTo(f)
91 if err != nil {
92 log.Fatalf("could not write canvas: %v", err)
93 }
94
95 err = f.Close()
96 if err != nil {
97 log.Fatalf("could not save canvas: %v", err)
98 }
99}

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
NewFunction · 0.92
NewLineFunction · 0.92
NewFunction · 0.92
NextPageMethod · 0.80
CloseMethod · 0.80
DrawMethod · 0.65
AddMethod · 0.45
WriteToMethod · 0.45

Tested by

no test coverage detected