當前位置: 首頁>>代碼示例>>Golang>>正文


Golang plot.New函數代碼示例

本文整理匯總了Golang中code/google/com/p/plotinum/plot.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Histogram

// Plots the historgram using plotinum
func Histogram(r RetCalc) {
	//eb := all_paths.End_balances()
	eb := make([]float64, len(r.All_paths), len(r.All_paths))
	incs := r.RunIncomes()
	for i := range incs {
		eb[i] = incs[i]
	}
	v := make(plotter.Values, len(eb))
	for i := range v {
		v[i] = eb[i]
	}

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

	p.Title.Text = "Histogram"
	h, err := plotter.NewHist(v, 100)
	if err != nil {
		panic(err)
	}
	//h.Normalize(1)
	p.Add(h)

	if err := p.Save(4, 4, "hist.png"); err != nil {
		panic(err)
	}
	fmt.Println(h)
}
開發者ID:kfatehi,項目名稱:retirement_calculator-go,代碼行數:31,代碼來源:helper.go

示例2: Example_quartPlots

// Example_quartPlots draws vertical quartile plots.
func Example_quartPlots() *plot.Plot {
	rand.Seed(int64(0))
	n := 100
	uniform := make(plotter.Values, n)
	normal := make(plotter.Values, n)
	expon := make(plotter.Values, n)
	for i := 0; i < n; i++ {
		uniform[i] = rand.Float64()
		normal[i] = rand.NormFloat64()
		expon[i] = rand.ExpFloat64()
	}

	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Quartile Plot"
	p.Y.Label.Text = "plotter.Values"

	p.Add(must(plotter.NewQuartPlot(0, uniform)).(*plotter.QuartPlot),
		must(plotter.NewQuartPlot(1, normal)).(*plotter.QuartPlot),
		must(plotter.NewQuartPlot(2, expon)).(*plotter.QuartPlot))

	// Set the X axis of the plot to nominal with
	// the given names for x=0, x=1 and x=2.
	p.NominalX("Uniform\nDistribution", "Normal\nDistribution",
		"Exponential\nDistribution")
	return p
}
開發者ID:jen6,項目名稱:plotinum,代碼行數:30,代碼來源:main.go

示例3: plotData

func plotData(name string, us, ys, ts, fs []float64) {
	p, err := plot.New()
	if err != nil {
		fmt.Printf("Cannot create new plot: %s\n", err)
		return
	}
	p.Title.Text = "Least-square fit of convex function"
	p.X.Min = -0.1
	p.X.Max = 2.3
	p.Y.Min = -1.1
	p.Y.Max = 7.2
	p.Add(plotter.NewGrid())

	pts := plotter.NewScatter(dataset(us, ys))
	pts.GlyphStyle.Color = color.RGBA{R: 255, A: 255}

	fit := plotter.NewLine(dataset(ts, fs))
	fit.LineStyle.Width = vg.Points(1)
	fit.LineStyle.Color = color.RGBA{B: 255, A: 255}

	p.Add(pts)
	p.Add(fit)
	if err := p.Save(4, 4, name); err != nil {
		fmt.Printf("Save to '%s' failed: %s\n", name, err)
	}
}
開發者ID:hrautila,項目名稱:go.opt,代碼行數:26,代碼來源:cvxfit.go

示例4: Plot

// Plot saves an image of the latency histogram to filePath. The extension of filePath defines
// the format to be used - png, svg, etc.
func Plot(h *latency.Histogram, description, filePath string) error {
	count := len(h.Buckets)
	xys := make(plotter.XYs, count)

	for bucket, freq := range h.Buckets {
		xys[bucket].X = float64(bucket)
		xys[bucket].Y = float64(freq)
	}

	p, err := plot.New()
	if err != nil {
		return fmt.Errorf("error generating plot: %v", err)
	}
	p.Title.Text = description
	p.X.Label.Text = fmt.Sprintf("Latency (%v resolution)", h.Resolution)
	p.Y.Label.Text = "Frequency"

	hh, err := plotter.NewHistogram(xys, count)
	if err != nil {
		return fmt.Errorf("error generating histogram: %v", err)

	}
	p.Add(hh)

	// Save the plot to a file. Units in inches (one inch == 72 points).
	fmt.Fprintf(os.Stderr, "Saving latency histogram to %v\n", filePath)
	return p.Save(8, 6, filePath)
}
開發者ID:nictuku,項目名稱:latency,代碼行數:30,代碼來源:plot.go

示例5: test1

func test1() {
	rand.Seed(int64(0))

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

	p.Title.Text = "Plotutil example"
	p.X.Label.Text = "X"
	p.Y.Label.Text = "Y"

	err = plotutil.AddLinePoints(p,
		"First", randomPoints(15),
		"Second", randomPoints(15),
		"Third", randomPoints(15))
	if err != nil {
		panic(err)
	}

	// Save the plot to a PNG file.
	if err := p.Save(4, 4, "points.png"); err != nil {
		panic(err)
	}
}
開發者ID:vvilp,項目名稱:go_test_example,代碼行數:25,代碼來源:test_plot.go

示例6: test_point

func test_point() {
	rand.Seed(int64(0))
	points_data := randomPoint(200)
	points_data2 := randomPoint(50)
	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	p.Title.Text = "Points"
	p.X.Label.Text = "X"
	p.Y.Label.Text = "Y"

	bs, _ := plotter.NewBubbles(points_data, vg.Points(5), vg.Points(5))
	bs2, _ := plotter.NewBubbles(points_data2, vg.Points(5), vg.Points(5))

	bs.Color = color.RGBA{R: 255, G: 0, B: 0, A: 255}
	bs2.Color = color.RGBA{R: 0, G: 255, B: 0, A: 255}
	p.Add(bs)
	p.Add(bs2)

	if err := p.Save(10, 10, "points.png"); err != nil {
		panic(err)
	}
}
開發者ID:vvilp,項目名稱:go_test_example,代碼行數:25,代碼來源:test_plot.go

示例7: plotData

func plotData(name string, xs, ys []float64) {
	p, err := plot.New()
	if err != nil {
		fmt.Printf("Cannot create new plot: %s\n", err)
		return
	}
	p.Title.Text = "Chernoff lower bound"
	p.X.Label.Text = "Sigma"
	p.X.Min = 0.2
	p.X.Max = 0.5
	p.Y.Label.Text = "Probability of correct detection"
	p.Y.Min = 0.9
	p.Y.Max = 1.0
	p.Add(plotter.NewGrid())

	l := plotter.NewLine(dataset(xs, ys))
	l.LineStyle.Width = vg.Points(1)
	//l.LineStyle.Dashes = []vg.Length(vg.Points(5), vg.Points(5))
	l.LineStyle.Color = color.RGBA{B: 255, A: 255}

	p.Add(l)
	if err := p.Save(4, 4, name); err != nil {
		fmt.Printf("Save to '%s' failed: %s\n", name, err)
	}
}
開發者ID:hrautila,項目名稱:go.opt,代碼行數:25,代碼來源:chernoff.go

示例8: Example_boxPlots

// Example_boxPlots draws vertical boxplots.
func Example_boxPlots() *plot.Plot {
	rand.Seed(int64(0))
	n := 100
	uniform := make(plotter.Values, n)
	normal := make(plotter.Values, n)
	expon := make(plotter.Values, n)
	for i := 0; i < n; i++ {
		uniform[i] = rand.Float64()
		normal[i] = rand.NormFloat64()
		expon[i] = rand.ExpFloat64()
	}

	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Box Plot"
	p.Y.Label.Text = "plotter.Values"

	// Make boxes for our data and add them to the plot.
	p.Add(plotter.NewBoxPlot(vg.Points(20), 0, uniform),
		plotter.NewBoxPlot(vg.Points(20), 1, normal),
		plotter.NewBoxPlot(vg.Points(20), 2, expon))

	// Set the X axis of the plot to nominal with
	// the given names for x=0, x=1 and x=2.
	p.NominalX("Uniform\nDistribution", "Normal\nDistribution",
		"Exponential\nDistribution")
	return p
}
開發者ID:jackielii,項目名稱:go-plotinum,代碼行數:31,代碼來源:main.go

示例9: draw

// draw is a generic plotter of labelled lines.
func draw(lines graph, title, xLabel, yLabel string) error {
	p, err := plot.New()
	if err != nil {
		return fmt.Errorf(err.Error())
	}

	p.Title.Text = title
	p.X.Label.Text = xLabel
	p.Y.Label.Text = yLabel

	i := 0
	for legend, data := range lines {
		i = i + 1
		l, err := plotter.NewLine(xys(data))
		if err != nil {
			return fmt.Errorf(err.Error())
		}

		p.Add(l)
		p.Legend.Add(legend, l)
		l.LineStyle.Color = getColor(i)
	}

	if err != nil {
		return fmt.Errorf(err.Error())
	}

	name := strings.Replace(strings.ToLower(title), " ", "-", -1)
	filename := fmt.Sprintf("strategy-%s.svg", name)
	if err := p.Save(8, 8, filename); err != nil {
		return fmt.Errorf(err.Error())
	}

	return nil
}
開發者ID:pingles,項目名稱:bandit-1,代碼行數:36,代碼來源:plot.go

示例10: Example_groupedHorizontalQuartPlots

func Example_groupedHorizontalQuartPlots() *plot.Plot {
	rand.Seed(int64(0))
	n := 100
	uniform := make(plotter.Values, n)
	normal := make(plotter.Values, n)
	expon := make(plotter.Values, n)
	for i := 0; i < n; i++ {
		uniform[i] = rand.Float64()
		normal[i] = rand.NormFloat64()
		expon[i] = rand.ExpFloat64()
	}

	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Box Plot"
	p.Y.Label.Text = "plotter.Values"

	w := vg.Points(10)
	for x := 0.0; x < 3.0; x++ {
		b0 := must(plotter.MakeHorizQuartPlot(x, uniform)).(plotter.HorizQuartPlot)
		b0.Offset = -w
		b1 := must(plotter.MakeHorizQuartPlot(x, normal)).(plotter.HorizQuartPlot)
		b2 := must(plotter.MakeHorizQuartPlot(x, expon)).(plotter.HorizQuartPlot)
		b2.Offset = w
		p.Add(b0, b1, b2)
	}
	p.Add(plotter.NewGlyphBoxes())

	p.NominalY("Group 0", "Group 1", "Group 2")
	return p
}
開發者ID:jen6,項目名稱:plotinum,代碼行數:33,代碼來源:main.go

示例11: Example_logo

// Draw the plotinum logo.
func Example_logo() *plot.Plot {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	plotter.DefaultLineStyle.Width = vg.Points(1)
	plotter.DefaultGlyphStyle.Radius = vg.Points(3)

	p.Y.Tick.Marker = plot.ConstantTicks([]plot.Tick{
		{0, "0"}, {0.25, ""}, {0.5, "0.5"}, {0.75, ""}, {1, "1"},
	})
	p.X.Tick.Marker = plot.ConstantTicks([]plot.Tick{
		{0, "0"}, {0.25, ""}, {0.5, "0.5"}, {0.75, ""}, {1, "1"},
	})

	pts := plotter.XYs{{0, 0}, {0, 1}, {0.5, 1}, {0.5, 0.6}, {0, 0.6}}
	line := must(plotter.NewLine(pts)).(*plotter.Line)
	scatter := must(plotter.NewScatter(pts)).(*plotter.Scatter)
	p.Add(line, scatter)

	pts = plotter.XYs{{1, 0}, {0.75, 0}, {0.75, 0.75}}
	line = must(plotter.NewLine(pts)).(*plotter.Line)
	scatter = must(plotter.NewScatter(pts)).(*plotter.Scatter)
	p.Add(line, scatter)

	pts = plotter.XYs{{0.5, 0.5}, {1, 0.5}}
	line = must(plotter.NewLine(pts)).(*plotter.Line)
	scatter = must(plotter.NewScatter(pts)).(*plotter.Scatter)
	p.Add(line, scatter)

	return p
}
開發者ID:jen6,項目名稱:plotinum,代碼行數:34,代碼來源:main.go

示例12: Example_errBars

// Example_errBars draws points and error bars.
func Example_errBars() *plot.Plot {

	type errPoints struct {
		plotter.XYs
		plotter.YErrors
		plotter.XErrors
	}

	rand.Seed(int64(0))
	n := 15
	data := errPoints{
		XYs:     randomPoints(n),
		YErrors: plotter.YErrors(randomError(n)),
		XErrors: plotter.XErrors(randomError(n)),
	}

	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	scatter := must(plotter.NewScatter(data)).(*plotter.Scatter)
	scatter.Shape = plot.CrossGlyph{}
	xerrs, err := plotter.NewXErrorBars(data)
	if err != nil {
		panic(err)
	}
	yerrs, err := plotter.NewYErrorBars(data)
	if err != nil {
		panic(err)
	}
	p.Add(scatter, xerrs, yerrs)
	p.Add(plotter.NewGlyphBoxes())

	return p
}
開發者ID:jen6,項目名稱:plotinum,代碼行數:36,代碼來源:main.go

示例13: Example_histogram

// An example of making a histogram.
func Example_histogram() *plot.Plot {
	rand.Seed(int64(0))
	n := 10000
	vals := make(plotter.Values, n)
	for i := 0; i < n; i++ {
		vals[i] = rand.NormFloat64()
	}

	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Histogram"
	h, err := plotter.NewHist(vals, 16)
	if err != nil {
		panic(err)
	}
	h.Normalize(1)
	p.Add(h)

	// The normal distribution function
	norm := plotter.NewFunction(stdNorm)
	norm.Color = color.RGBA{R: 255, A: 255}
	norm.Width = vg.Points(2)
	p.Add(norm)

	return p
}
開發者ID:jen6,項目名稱:plotinum,代碼行數:29,代碼來源:main.go

示例14: main

func main() {
	// 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 := plotutil.NewErrorPoints(plotutil.MeanAndConf95, pts...)
	medMinMax := plotutil.NewErrorPoints(plotutil.MedianAndMinMax, pts...)
	plotutil.AddLinePoints(plt,
		"mean and 95% confidence", mean95,
		"median and minimum and maximum", medMinMax)
	plotutil.AddErrorBars(plt, mean95, medMinMax)
	plotutil.AddScatters(plt, pts[0], pts[1], pts[2], pts[3], pts[4])

	plt.Save(4, 4, "errpoints.png")
}
開發者ID:jackielii,項目名稱:go-plotinum,代碼行數:29,代碼來源:main.go

示例15: createLine

// createLine creates a line graph from provided x,y data and title
func createLine(xdat, ydat [][]float64, ylab []string, title string) {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Add(plotter.NewGrid())
	p.Title.Text = title
	p.Legend.Top = true
	p.Legend.XOffs = -10.0
	p.Legend.YOffs = -10.0

	var scatdata xyer
	var s *plotter.Line
	for i, _ := range ydat {
		scatdata = xyer{xdat[i], ydat[i]}
		s = plotter.NewLine(scatdata)
		s.LineStyle.Width = 2
		s.LineStyle.Color = cols[i]
		p.Add(s)
		p.Legend.Add(ylab[i], s)
	}
	p.X.Max = 2.5
	p.Y.Max = 3.5
	p.X.Label.Text = "Time / ps"
	p.Y.Label.Text = "Probability density"

	if err := p.Save(5, 5, "out/"+title+".png"); err != nil {
		panic(err)
	}
}
開發者ID:swook,項目名稱:go.iccp,代碼行數:31,代碼來源:plot.go


注:本文中的code/google/com/p/plotinum/plot.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。