Example #1
0
func PlotLine(pts, pts2 plotter.XYs, w []float64, b float64, path string) {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.X.Label.Text = "x"
	p.Y.Label.Text = "y"

	x := []float64{}
	y := []float64{}
	for i := range make([]float64, 150) {
		bx := float64(i)*0.1 - 6.0
		x = append(x, bx)
		y = append(y, -b/w[1]-w[0]/w[1]*bx)
	}
	pts_res := makeLine(x, y)
	err = plotutil.AddScatters(p,
		"Class 0", pts,
		"Class 1", pts2,
	)
	if err != nil {
		panic(err)
	}
	err = plotutil.AddLines(p,
		"Line", pts_res,
	)
	if err != nil {
		panic(err)
	}
	if err := p.Save(10*vg.Inch, 10*vg.Inch, path); err != nil {
		panic(err)
	}
}
Example #2
0
func PlotSample(pts, pts2 plotter.XYs, path string) {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.X.Label.Text = "x"
	p.Y.Label.Text = "y"
	err = plotutil.AddScatters(p,
		"Class 0", pts,
		"Class 1", pts2,
	)
	if err != nil {
		panic(err)
	}
	if err := p.Save(10*vg.Inch, 10*vg.Inch, path); err != nil {
		panic(err)
	}
}
Example #3
0
func PlotError(errors []float64, path string) {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.X.Label.Text = "iteration"
	p.Y.Label.Text = "error"
	pts_err := makePoints(errors)
	err = plotutil.AddScatters(p,
		"Error", pts_err,
	)
	if err != nil {
		panic(err)
	}
	if err := p.Save(10*vg.Inch, 10*vg.Inch, path); err != nil {
		panic(err)
	}
}
Example #4
0
// Example_errpoints draws some error points.
func Example_errpoints() *plot.Plot {
	// Get some random data.
	n, m := 5, 10
	pts := make([]plotter.XYer, n)
	for i := range pts {
		xys := make(plotter.XYs, m)
		pts[i] = xys
		center := float64(i)
		for j := range xys {
			xys[j].X = center + (rand.Float64() - 0.5)
			xys[j].Y = center + (rand.Float64() - 0.5)
		}
	}

	plt, err := plot.New()
	if err != nil {
		panic(err)
	}

	mean95, err := plotutil.NewErrorPoints(plotutil.MeanAndConf95, pts...)
	if err != nil {
		panic(err)
	}
	medMinMax, err := plotutil.NewErrorPoints(plotutil.MedianAndMinMax, pts...)
	if err != nil {
		panic(err)
	}
	plotutil.AddLinePoints(plt,
		"mean and 95% confidence", mean95,
		"median and minimum and maximum", medMinMax)
	if err := plotutil.AddErrorBars(plt, mean95, medMinMax); err != nil {
		panic(err)
	}
	if err := plotutil.AddScatters(plt, pts[0], pts[1], pts[2], pts[3], pts[4]); err != nil {
		panic(err)
	}

	return plt
}