Created
June 19, 2012 22:14
-
-
Save iand/2956833 to your computer and use it in GitHub Desktop.
Plotinum Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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