// +build ignore
// A simple test program to test plotters.
package main
import (
"math"
"math/rand"
)
func main() {
p, err := plot.New()
if err != nil {
panic(err)
}
p.Title.Text = "Functions"
p.X.Label.Text = "X"
p.Y.Label.Text = "Y"
p.Y.Scale = plot.LogScale
p.Y.Tick.Marker = plot.LogTicks
exp := plotter.NewFunction(func(x float64) float64 { return math.Pow(10, x) })
p.Add(exp)
p.Legend.Add("10^x", exp)
p.Legend.ThumbnailWidth = vg.Inches(0.5)
err = plotutil.AddLinePoints(p,
"First", randomPoints(15),
"Second", randomPoints(15),
"Third", randomPoints(15))
if err != nil {
panic(err)
}
if err := p.Save(4, 4, "exp2.eps"); err != nil {
panic(err)
}
}
// randomPoints returns some random x, y points.
func randomPoints(n int) plotter.XYs {
pts := make(plotter.XYs, n)
for i := range pts {
if i == 0 {
pts[i].X = rand.Float64()
} else {
pts[i].X = pts[i-1].X + rand.Float64()
}
pts[i].Y = pts[i].X + 100*rand.Float64()
}
return pts
}