An example of making a LaTeX plot.
()
| 19 | |
| 20 | // An example of making a LaTeX plot. |
| 21 | func Example() { |
| 22 | p := plot.New() |
| 23 | // p.HideAxes() |
| 24 | p.Title.Text = `A scatter plot: $\sqrt{\frac{e^{3i\pi}}{2\cos 3\pi}}$` |
| 25 | p.Title.TextStyle.Font.Size = 16 |
| 26 | p.X.Label.Text = `$x = \eta$` |
| 27 | p.Y.Label.Text = `$y$ is some $\Phi$` |
| 28 | |
| 29 | scatter1, err := plotter.NewScatter(plotter.XYs{{X: 1, Y: 1}, {X: 0, Y: 1}, {X: 0, Y: 0}}) |
| 30 | if err != nil { |
| 31 | log.Fatal(err) |
| 32 | } |
| 33 | scatter1.Color = color.RGBA{R: 255, A: 200} |
| 34 | |
| 35 | scatter2, err := plotter.NewScatter(plotter.XYs{{X: 1, Y: 0}, {X: 1, Y: 0.5}}) |
| 36 | if err != nil { |
| 37 | log.Fatal(err) |
| 38 | } |
| 39 | scatter2.GlyphStyle.Shape = draw.PyramidGlyph{} |
| 40 | scatter2.GlyphStyle.Radius = 2 |
| 41 | scatter2.Color = color.RGBA{B: 255, A: 200} |
| 42 | |
| 43 | p.Add(scatter1, scatter2) |
| 44 | |
| 45 | txtFont := p.TextHandler.Cache().Lookup( |
| 46 | p.X.Label.TextStyle.Font, |
| 47 | p.X.Label.TextStyle.Font.Size, |
| 48 | ) |
| 49 | |
| 50 | c := vgtex.NewDocument(5*vg.Centimeter, 5*vg.Centimeter) |
| 51 | p.Draw(draw.New(c)) |
| 52 | |
| 53 | c.SetColor(color.Black) |
| 54 | c.FillString(txtFont, vg.Point{X: 2.5 * vg.Centimeter, Y: 2.5 * vg.Centimeter}, "x") |
| 55 | |
| 56 | f, err := os.Create("testdata/scatter_" + runtime.GOARCH + ".tex") |
| 57 | if err != nil { |
| 58 | log.Fatal(err) |
| 59 | } |
| 60 | defer f.Close() |
| 61 | |
| 62 | if _, err = c.WriteTo(f); err != nil { |
| 63 | log.Fatal(err) |
| 64 | } |
| 65 | err = f.Close() |
| 66 | if err != nil { |
| 67 | log.Fatal(err) |
| 68 | } |
| 69 | } |
nothing calls this directly
no test coverage detected