• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang plot.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/gonum/plot.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: makeRegPlots

// makeRegPlots makes the second plot including the raw input data and the
// trained function.
func makeRegPlots(xys1, xys2 plotter.XYs) error {

	// Create a plot value.
	p, err := plot.New()
	if err != nil {
		return errors.Wrap(err, "Could not create plot object")
	}

	// Label the plot.
	p.Title.Text = "Daily Counts of Go Repos Created"
	p.X.Label.Text = "Days from Jan. 1, 2013"
	p.Y.Label.Text = "Count"

	// Add both sets of points, predicted and actual, to the plot.
	if err := plotutil.AddLinePoints(p, "Actual", xys1, "Predicted", xys2); err != nil {
		return errors.Wrap(err, "Could not add lines to plot")
	}

	// Save the plot.
	if err := p.Save(7*vg.Inch, 4*vg.Inch, "regression.png"); err != nil {
		return errors.Wrap(err, "Could not output plot")
	}

	return nil
}
开发者ID:Rahmadkurniawan,项目名称:2016-talks,代码行数:27,代码来源:linearregression.go


示例2: 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 = draw.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:kc-cylon5,项目名称:gogui,代码行数:36,代码来源:main.go


示例3: 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:kc-cylon5,项目名称:gogui,代码行数:29,代码来源:main.go


示例4: 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:kc-cylon5,项目名称:gogui,代码行数:30,代码来源:main.go


示例5: 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:kc-cylon5,项目名称:gogui,代码行数:33,代码来源:main.go


示例6: Example_functions

// Example_functions draws some functions.
func Example_functions() *plot.Plot {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Functions"
	p.X.Label.Text = "X"
	p.Y.Label.Text = "Y"

	quad := plotter.NewFunction(func(x float64) float64 { return x * x })
	quad.Color = color.RGBA{B: 255, A: 255}

	exp := plotter.NewFunction(func(x float64) float64 { return math.Pow(2, x) })
	exp.Dashes = []vg.Length{vg.Points(2), vg.Points(2)}
	exp.Width = vg.Points(2)
	exp.Color = color.RGBA{G: 255, A: 255}

	sin := plotter.NewFunction(func(x float64) float64 { return 10*math.Sin(x) + 50 })
	sin.Dashes = []vg.Length{vg.Points(4), vg.Points(5)}
	sin.Width = vg.Points(4)
	sin.Color = color.RGBA{R: 255, A: 255}

	p.Add(quad, exp, sin)
	p.Legend.Add("x^2", quad)
	p.Legend.Add("2^x", exp)
	p.Legend.Add("10*sin(x)+50", sin)
	p.Legend.ThumbnailWidth = 0.5 * vg.Inch

	p.X.Min = 0
	p.X.Max = 10
	p.Y.Min = 0
	p.Y.Max = 100
	return p
}
开发者ID:kc-cylon5,项目名称:gogui,代码行数:35,代码来源:main.go


示例7: Example_groupedBoxPlots

// Example_groupedBoxPlots draws vertical boxplots.
func Example_groupedBoxPlots() *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(20)
	for x := 0.0; x < 3.0; x++ {
		b0 := must(plotter.NewBoxPlot(w, x, uniform)).(*plotter.BoxPlot)
		b0.Offset = -w - vg.Points(3)
		b1 := must(plotter.NewBoxPlot(w, x, normal)).(*plotter.BoxPlot)
		b2 := must(plotter.NewBoxPlot(w, x, expon)).(*plotter.BoxPlot)
		b2.Offset = w + vg.Points(3)
		p.Add(b0, b1, b2)
	}

	// Set the X axis of the plot to nominal with
	// the given names for x=0, x=1 and x=2.
	p.NominalX("Group 0", "Group 1", "Group 2")
	return p
}
开发者ID:kc-cylon5,项目名称:gogui,代码行数:35,代码来源:main.go


示例8: CreateImage

// CreateImage creates graph of nyanpass
func (n *Nyanpass) CreateImage(fileName string) error {
	if n.Counts == nil {
		return errors.New("Count is not defined.")
	}

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

	bar, err := plotter.NewBarChart(n.Counts, vg.Points(30))
	if err != nil {
		return err
	}
	bar.LineStyle.Width = vg.Length(0)
	bar.Color = plotutil.Color(2)

	p.Add(bar)
	p.Title.Text = "Nyanpass Graph"
	p.X.Label.Text = "Days"
	p.Y.Label.Text = "Nyanpass count"
	p.NominalX(n.labels...)
	p.Y.Tick.Marker = RelabelTicks{}

	if err := p.Save(6*vg.Inch, 6*vg.Inch, fileName); err != nil {
		return err
	}
	n.imagePath = fileName
	return nil
}
开发者ID:Rompei,项目名称:nyanpass-graph2,代码行数:31,代码来源:nyanpass.go


示例9: 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:kc-cylon5,项目名称:gogui,代码行数:34,代码来源:main.go


示例10: plotSingle

func plotSingle(df *DataFrame, name string) {
	p, err := plot.New()
	if err != nil {
		log.Fatal(err)
	}

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

	err = plotutil.AddLinePoints(p, name, df.PlotPoints())
	if err != nil {
		log.Fatal(err)
	}

	c := vgsvg.New(16*vg.Inch, 9*vg.Inch)

	can := draw.New(c)

	p.Draw(can)
	p.Save(16*vg.Inch/2, 9*vg.Inch/2, fmt.Sprintf("graphs/%s.png", name))
	f, err := os.Create(fmt.Sprintf("graphs/%s.svg", name))
	if err != nil {
		log.Fatal(err)
	}

	c.WriteTo(f)

}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:28,代码来源:plot_test.go


示例11: ExampleHeatMap

func ExampleHeatMap() {
	m := unitGrid{mat64.NewDense(3, 4, []float64{
		1, 2, 3, 4,
		5, 6, 7, 8,
		9, 10, 11, 12,
	})}
	h := NewHeatMap(m, palette.Heat(12, 1))

	p, err := plot.New()
	if err != nil {
		log.Panic(err)
	}
	p.Title.Text = "Heat map"

	p.Add(h)

	p.X.Padding = 0
	p.Y.Padding = 0
	p.X.Max = 3.5
	p.Y.Max = 2.5

	err = p.Save(100, 100, "testdata/heatMap.png")
	if err != nil {
		log.Panic(err)
	}
}
开发者ID:zzn01,项目名称:plot,代码行数:26,代码来源:heat_test.go


示例12: PlotLine

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)
	}
}
开发者ID:fisproject,项目名称:go-msgd,代码行数:33,代码来源:plot_util.go


示例13: plotDensity

func plotDensity(results []densityResult) {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	p.Title.Text = "Density"
	p.X.Label.Text = "Seconds"
	p.Y.Label.Text = "Number of Pods"

	err = plotutil.AddLinePoints(p,
		"Created", getCreatedPoints(results),
		"Running", getRunningPoints(results),
		"Pending", getPendingPoints(results),
		"Waiting", getWaitingPoints(results))
	if err != nil {
		panic(err)
	}

	// Save the plot to a SVG file.
	if err := p.Save(10*vg.Inch, 10*vg.Inch, "density-all.svg"); err != nil {
		panic(err)
	}

	fmt.Println("successfully plotted density graph to density-all.svg")
}
开发者ID:dalanlan,项目名称:kscale,代码行数:26,代码来源:main.go


示例14: plotDensity

func plotDensity(rs1, rs2 []result, ftype string) {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	p.Title.Text = "Scheduler Benchmark"
	p.X.Label.Text = "Seconds"

	var filename string
	switch ftype {
	case "total":
		p.Y.Label.Text = "Number of Pods"
		err = plotutil.AddLinePoints(p,
			"Total-new", getTotal(rs1),
			"Total-old", getTotal(rs2))
		filename = "schedule-total.png"
	case "rate":
		p.Y.Label.Text = "Rate of Scheduling"
		err = plotutil.AddLinePoints(p,
			"Rate-new", getRate(rs1),
			"Rate-old", getRate(rs2))
		filename = "schedule-rate.png"
	}
	if err != nil {
		panic(err)
	}

	if err := p.Save(10*vg.Inch, 10*vg.Inch, filename); err != nil {
		panic(err)
	}

	fmt.Println("successfully plotted density graph to", filename)
}
开发者ID:coreos,项目名称:kscale,代码行数:34,代码来源:main.go


示例15: Plot

// Plot plots only 2-dimensional cluster and points
func (em EM) Plot(fileid int, directory string) {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "EM-Algorithm Plot"
	p.X.Label.Text = "X"
	p.Y.Label.Text = "Y"
	bs, err := plotter.NewBubbles(em.clusterTriples(), vg.Points(30), vg.Points(80))
	if err != nil {
		panic(err)
	}
	bs.Color = color.RGBA{R: 255, B: 255, A: 255}
	p.Add(bs)

	ss, err := plotter.NewScatter(em.dataTriples())
	if err != nil {
		panic(err)
	}
	ss.Color = color.Black
	p.Add(ss)

	filename := directory + fmt.Sprintf("%03d", fileid) + ".png"
	if err := p.Save(10*vg.Inch, 10*vg.Inch, filename); err != nil {
		panic(err)
	}
}
开发者ID:6br,项目名称:goem,代码行数:28,代码来源:plot.go


示例16: 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:jd1123,项目名称:retirement_calculator-go,代码行数:31,代码来源:helper.go


示例17: makePlots

// makePlots creates and saves the first of our plots showing the raw input data.
func makePlots(xys plotter.XYs) error {

	// Create a new plot.
	p, err := plot.New()
	if err != nil {
		return errors.Wrap(err, "Could not create plot object")
	}

	// Label the new plot.
	p.Title.Text = "Daily Counts of Go Repos Created"
	p.X.Label.Text = "Days from Jan. 1, 2013"
	p.Y.Label.Text = "Count"

	// Add the prepared points to the plot.
	if err = plotutil.AddLinePoints(p, "Counts", xys); err != nil {
		return errors.Wrap(err, "Could not add lines to plot")
	}

	// Save the plot to a PNG file.
	if err := p.Save(7*vg.Inch, 4*vg.Inch, "countseries.png"); err != nil {
		return errors.Wrap(err, "Could not output plot")
	}

	return nil
}
开发者ID:Rahmadkurniawan,项目名称:2016-talks,代码行数:26,代码来源:counts.go


示例18: PlotGraph

func PlotGraph(title string, timestamps []int64, w io.Writer) error {
	p, err := plot.New()
	if err != nil {
		return err
	}

	p.Title.Text = title
	p.X.Label.Text = "Time"
	p.Y.Label.Text = "Number of stars"
	p.Y.Min = 0

	points := make(plotter.XYs, len(timestamps))
	for i, timestamp := range timestamps {
		points[i].X = float64(timestamp)
		points[i].Y = float64(i + 1)
	}
	plotutil.AddLinePoints(p, "Stars", points)

	c := vgimg.New(4*vg.Inch, 4*vg.Inch)
	cpng := vgimg.PngCanvas{c}

	p.Draw(draw.New(cpng))

	if _, err := cpng.WriteTo(w); err != nil {
		return err
	}
	return nil
}
开发者ID:bronzdoc,项目名称:stargraph,代码行数:28,代码来源:plot.go


示例19: GeneratePlot

func GeneratePlot(x, y []float64, title, xLabel, yLabel, legendLabel, fileName string) {
	outPlotPoints := make(plotter.XYs, len(x))

	for i, _ := range x {
		outPlotPoints[i].X = x[i]
		outPlotPoints[i].Y = y[i]
	}

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

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

	err = plotutil.AddLines(outPlot,
		legendLabel, outPlotPoints)
	if err != nil {
		panic(err)
	}

	if err := outPlot.Save(6*vg.Inch, 6*vg.Inch, fileName); err != nil {
		panic(err)
	}
}
开发者ID:wenkesj,项目名称:sn,代码行数:27,代码来源:plots.go


示例20: GeneratePlots

func GeneratePlots(x, y [][]float64, title, xLabel, yLabel, fileName string, legendLabel []string) {
	outPlotPoints := make([]plotter.XYs, len(x))
	outPlots := make([]*plot.Plot, len(x))

	for i, _ := range outPlotPoints {
		outPlot, err := plot.New()
		outPlots[i] = outPlot
		outPlots[i].Title.Text = title
		outPlots[i].X.Label.Text = xLabel
		outPlots[i].Y.Label.Text = yLabel
		outPlotPoints[i] = make(plotter.XYs, len(x[0]))
		for j, _ := range x[0] {
			outPlotPoints[i][j].X = x[i][j]
			outPlotPoints[i][j].Y = y[i][j]
		}
		err = plotutil.AddLines(outPlots[i],
			legendLabel[i], outPlotPoints[i])
		if err != nil {
			panic(err)
		}

		if err = outPlot.Save(6*vg.Inch, 6*vg.Inch, (fileName+strconv.FormatInt(int64(i), 16))+".png"); err != nil {
			panic(err)
		}
	}
}
开发者ID:wilseypa,项目名称:rphash-golang,代码行数:26,代码来源:main.go



注:本文中的github.com/gonum/plot.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang plot.Plot类代码示例发布时间:2022-05-23
下一篇:
Golang mat64.Vector类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap