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

Function TestPersistency

gob/gob_test.go:26–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func TestPersistency(t *testing.T) {
27 rnd := rand.New(rand.NewPCG(1, 1))
28
29 // Get some random points
30 n := 15
31 scatterData := randomPoints(n, rnd)
32 lineData := randomPoints(n, rnd)
33 linePointsData := randomPoints(n, rnd)
34
35 p := plot.New()
36 p.Title.Text = "Plot Example"
37 p.X.Label.Text = "X"
38 p.Y.Label.Text = "Y"
39 // Use a custom tick marker function that computes the default
40 // tick marks and re-labels the major ticks with commas.
41 p.Y.Tick.Marker = commaTicks{}
42
43 // Draw a grid behind the data
44 p.Add(plotter.NewGrid())
45 // Make a scatter plotter and set its style.
46 s, err := plotter.NewScatter(scatterData)
47 if err != nil {
48 panic(err)
49 }
50 s.GlyphStyle.Color = color.RGBA{R: 255, B: 128, A: 255}
51
52 // Make a line plotter and set its style.
53 l, err := plotter.NewLine(lineData)
54 if err != nil {
55 panic(err)
56 }
57 l.LineStyle.Width = vg.Points(1)
58 l.LineStyle.Dashes = []vg.Length{vg.Points(5), vg.Points(5)}
59 l.LineStyle.Color = color.RGBA{B: 255, A: 255}
60
61 // Make a line plotter with points and set its style.
62 lpLine, lpPoints, err := plotter.NewLinePoints(linePointsData)
63 if err != nil {
64 panic(err)
65 }
66 lpLine.Color = color.RGBA{G: 255, A: 255}
67 lpPoints.Shape = draw.PyramidGlyph{}
68 lpPoints.Color = color.RGBA{R: 255, A: 255}
69
70 // Add the plotters to the plot, with a legend
71 // entry for each
72 p.Add(s, l, lpLine, lpPoints)
73 p.Legend.Add("scatter", s)
74 p.Legend.Add("line", l)
75 p.Legend.Add("line points", lpLine, lpPoints)
76
77 // Save the plot to a PNG file.
78 err = p.Save(4, 4, "test-persistency.png")
79 if err != nil {
80 t.Fatalf("error saving to PNG: %v\n", err)
81 }
82 defer os.Remove("test-persistency.png")
83

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
NewGridFunction · 0.92
NewScatterFunction · 0.92
NewLineFunction · 0.92
PointsFunction · 0.92
NewLinePointsFunction · 0.92
randomPointsFunction · 0.85
SaveMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected