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

Function ExampleLatex

text/latex_example_test.go:24–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22)
23
24func ExampleLatex() {
25 fonts := font.NewCache(liberation.Collection())
26 plot.DefaultTextHandler = text.Latex{
27 Fonts: fonts,
28 }
29
30 p := plot.New()
31 p.Title.Text = `$f(x) = \sqrt{\alpha x \Gamma}$`
32 p.X.Label.Text = `$\frac{\sqrt{x}}{2\pi\Gamma\gamma}$`
33 p.Y.Label.Text = `$\beta$`
34
35 p.X.Min = -1
36 p.X.Max = +1
37 p.Y.Min = -1
38 p.Y.Max = +1
39
40 labels, err := plotter.NewLabels(plotter.XYLabels{
41 XYs: []plotter.XY{
42 {X: +0.0, Y: +0.0},
43 {X: -0.9, Y: -0.9},
44 {X: +0.6, Y: +0.0},
45 {X: +0.5, Y: -0.9},
46 },
47 Labels: []string{
48 `$\frac{\sqrt{x}}{2\pi\Gamma\gamma}$`,
49 `$LaTeX$`,
50 "plain",
51 `$\frac{\sqrt{x}}{2\beta}$`,
52 },
53 })
54 if err != nil {
55 log.Fatalf("could not create labels: %+v", err)
56 }
57 labels.TextStyle[0].Font.Size = 24
58 labels.TextStyle[0].Color = color.RGBA{B: 255, A: 255}
59 labels.TextStyle[0].XAlign = draw.XCenter
60 labels.TextStyle[0].YAlign = draw.YCenter
61
62 labels.TextStyle[1].Font.Size = 24
63 labels.TextStyle[1].Color = color.RGBA{R: 255, A: 255}
64 labels.TextStyle[1].Rotation = math.Pi / 4
65
66 labels.TextStyle[2].Font.Size = 24
67 labels.TextStyle[2].Rotation = math.Pi / 4
68 labels.TextStyle[2].YAlign = draw.YCenter
69 labels.TextStyle[2].Handler = &text.Plain{Fonts: fonts}
70
71 labels.TextStyle[3].Font.Size = 24
72 labels.TextStyle[3].Rotation = math.Pi / 2
73
74 p.Add(labels)
75 p.Add(plotter.NewGlyphBoxes())
76 p.Add(plotter.NewGrid())
77
78 err = p.Save(10*vg.Centimeter, 5*vg.Centimeter, "testdata/latex_"+runtime.GOARCH+".png")
79 if err != nil {
80 log.Fatalf("could not save plot: %+v", err)
81 }

Callers

nothing calls this directly

Calls 8

NewCacheFunction · 0.92
CollectionFunction · 0.92
NewFunction · 0.92
NewLabelsFunction · 0.92
NewGlyphBoxesFunction · 0.92
NewGridFunction · 0.92
SaveMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected