Skip to content

Instantly share code, notes, and snippets.

@iand
Created June 19, 2012 22:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iand/2956833 to your computer and use it in GitHub Desktop.
Save iand/2956833 to your computer and use it in GitHub Desktop.
Plotinum Example
package main
import (
"code.google.com/p/plotinum/plot"
"code.google.com/p/plotinum/vg"
"code.google.com/p/plotinum/vg/veceps"
"math/rand"
)
func main() {
// Get some data to plot.
pts := make(plot.XYs, 10)
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 = rand.Float64()
}
// Make an encapsulated postscript DrawArea
w, h := vg.Inches(3), vg.Inches(2)
da := plot.NewDrawArea(veceps.New(w, h, "test"), w, h)
// Make our plot and set some labels.
p, err := plot.New()
if err != nil {
panic(err)
}
p.Title.Text = "Plot Title"
p.X.Label.Text = "X Values"
p.Y.Label.Text = "Y Values"
line := plot.Line{pts, plot.DefaultLineStyle}
scatter := plot.Scatter{pts, plot.DefaultGlyphStyle}
p.AddData(line, scatter)
p.Legend.AddEntry("line", line, scatter)
p.Legend.Top = true
p.Draw(da)
// Save to test.eps
err = da.Canvas.(*veceps.Canvas).Save("test.eps")
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment