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

Golang plotter.NewLine函数代码示例

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

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



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

示例1: 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


示例2: plotLine

func plotLine(xy plotter.XYs) (image.Image, error) {

	p, err := plot.New()
	if err != nil {
		return nil, err
	}
	p.HideAxes()
	p.BackgroundColor = &color.RGBA{0, 0, 0, 255}

	//s, err := NewSparkLines(xy)
	s, err := plotter.NewLine(xy)
	if err != nil {
		return nil, err
	}
	s.Color = &color.RGBA{0, 255, 0, 128}
	p.Add(s)

	// Draw the plot to an in-memory image.
	// _, rows, _ := terminal.GetSize(0)
	charWidth := optCharWidth
	charHeight := optCharHeight
	//width := cols * charWidth
	height := optRows * charHeight

	img := image.NewRGBA(image.Rect(0, 0, 5+(len(xy)*charWidth), height))
	canvas := vgimg.NewImage(img)
	da := plot.MakeDrawArea(canvas)
	p.Draw(da)

	return img, nil
}
开发者ID:raff,项目名称:go-sparkline,代码行数:31,代码来源:plot.go


示例3: 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


示例4: AddLines

// AddLines adds Line plotters to a plot.
// The variadic arguments must be either strings
// or plotter.XYers.  Each plotter.XYer is added to
// the plot using the next color and dashes
// shape via the Color and Dashes functions.
// If a plotter.XYer is immediately preceeded by
// a string then a legend entry is added to the plot
// using the string as the name.
//
// If an error occurs then none of the plotters are added
// to the plot, and the error is returned.
func AddLines(plt *plot.Plot, vs ...interface{}) error {
	var ps []plot.Plotter
	names := make(map[*plotter.Line]string)
	name := ""
	var i int
	for _, v := range vs {
		switch t := v.(type) {
		case string:
			name = t

		case plotter.XYer:
			l, err := plotter.NewLine(t)
			if err != nil {
				return err
			}
			l.Color = Color(i)
			l.Dashes = Dashes(i)
			i++
			ps = append(ps, l)
			if name != "" {
				names[l] = name
				name = ""
			}

		default:
			panic(fmt.Sprintf("AddLines handles strings and plotter.XYers, got %T", t))
		}
	}
	plt.Add(ps...)
	for p, n := range names {
		plt.Legend.Add(n, p)
	}
	return nil
}
开发者ID:venliong,项目名称:plotinum,代码行数:45,代码来源:add.go


示例5: 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


示例6: 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


示例7: 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


示例8: PlotBands

func PlotBands(symbol string, all []bands.Band) {
	dclose := make(plotter.XYs, len(all))
	dsma := make(plotter.XYs, len(all))
	dup := make(plotter.XYs, len(all))
	ddown := make(plotter.XYs, len(all))

	for i, b := range all {
		dclose[i].X = float64(-1 * i)
		dclose[i].Y = b.Close

		dsma[i].X = float64(-1 * i)
		dsma[i].Y = b.SMA

		dup[i].X = float64(-1 * i)
		dup[i].Y = b.Up

		ddown[i].X = float64(-1 * i)
		ddown[i].Y = b.Down
	}

	p, _ := plot.New()

	p.Title.Text = fmt.Sprintf("Bollinger Bands: %s", symbol)
	p.X.Label.Text = "Time (Days)"
	p.Y.Label.Text = "Value"

	p.Add(plotter.NewGrid())

	lclose, _ := plotter.NewLine(dclose)

	lsma, _ := plotter.NewLine(dsma)
	lsma.LineStyle.Color = color.RGBA{B: 255, A: 255}

	lup, _ := plotter.NewLine(dup)
	lup.LineStyle.Color = color.RGBA{R: 255, A: 255}

	ldown, _ := plotter.NewLine(ddown)
	ldown.LineStyle.Color = color.RGBA{G: 255, A: 255}

	p.Add(lclose, lsma, lup, ldown)
	p.Legend.Add("Closing", lclose)
	p.Legend.Add("SMA", lsma)
	p.Legend.Add("Up", lup)
	p.Legend.Add("Down", ldown)

	p.Save(16, 9, fmt.Sprintf("%s.png", symbol))
}
开发者ID:juantascon,项目名称:bollinger-bands,代码行数:47,代码来源:plot.go


示例9: main

func main() {
	fmt.Println("Running...")
	start := time.Now()

	count := 0
	pt = make([]plotter.XYs, 0)
	for n := nMin; n <= nMax; n *= 2 {
		y1 = make([]float64, n)
		y2 = make([]float64, n)
		pt = append(pt, make(plotter.XYs, n))

		y1[0] = 1.0
		y2[0] = 3.0
		h = (tMax - tMin) / float64(n-1)

		for i := 1; i < n; i++ {
			y1[i] = y1[i-1] + 2*y1[i-1]*(1-y2[i-1])*h
			y2[i] = y2[i-1] - y2[i-1]*(1-y1[i-1])*h
		}

		for i := 0; i < n; i++ {
			pt[count][i].X = y1[i]
			pt[count][i].Y = y2[i]
		}
		count++
	}
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = fmt.Sprintf("Enright and Pryce #B1:Euler")
	p.Y.Label.Text = "y2(t)"
	p.X.Label.Text = "y1(t)"

	n := nMin
	for i := 0; i < count; i++ {
		l := plotter.NewLine(pt[i])
		l.LineStyle.Width = vg.Points(1)
		l.LineStyle.Color = color.RGBA{R: 255 / uint8(i+1), G: 255 / uint8(i+1),
			B: 255 / uint8(i+1), A: 255}
		p.Add(l)
		n *= 2
	}
	p.X.Min = 0
	p.X.Max = 6.5
	p.Y.Min = 0
	p.Y.Max = 6.5

	// Save the plot to a PNG file.
	if err := p.Save(6, 6, "euler_test.png"); err != nil {
		panic(err)
	}

	fmt.Println(time.Since(start))
	fmt.Println("...program terminated successfully!")
}
开发者ID:akonneker,项目名称:scicomp,代码行数:56,代码来源:odehw15.go


示例10: DataTableToPng

func DataTableToPng(b *bytes.Buffer, dt *db.DataTable, title string, width, height float64, xLabel string) error {
	p, err := plot.New()
	if err != nil {
		return err
	}

	p.Title.Text = title
	p.X.Label.Text = xLabel
	p.Y.Label.Text = "msec" // TODO: Fix this.

	// TODO: need new ticker function to handle equalX (while keeping xLabel as selected)
	if xLabel == common.TimeName {
		p.X.Tick.Marker = TimeTicks
	}
	p.Legend.Top = true

	numColumns := len(dt.ColumnNames)
	lines := make([]plotter.XYs, numColumns-1) // Skip X column.

	for _, dRow := range dt.Data {
		xp := (*dRow)[0]
		if xp != nil {
			for col := 1; col < numColumns; col++ { // Skip X column.
				yp := (*dRow)[col]
				if yp != nil {
					lines[col-1] = append(lines[col-1], struct{ X, Y float64 }{X: *xp, Y: *yp})
				}
			}
		}
	}

	colorList := getColors(numColumns - 1) // Skip X column.

	for i, line := range lines {
		columnName := dt.ColumnNames[i+1]
		l, err := plotter.NewLine(line)
		if err != nil {
			return err
		}
		if strings.Index(columnName, common.RegressNamePrefix) == 0 { // If regression value.
			l.LineStyle.Color = color.RGBA{255, 0, 0, 255}
			l.LineStyle.Width = vg.Points(2.0)
		} else {
			l.LineStyle.Color = colorList[i]
			l.LineStyle.Width = vg.Points(1.5)
		}
		p.Add(l)
		p.Legend.Add(columnName, l)
	}

	tPng := time.Now()
	drawPng(b, p, width, height)
	glog.V(3).Infof("PERF: makePng time: %v", time.Now().Sub(tPng))
	return nil
}
开发者ID:meteorfox,项目名称:tsviewdb,代码行数:55,代码来源:png.go


示例11: linesPlot

func linesPlot() *plot.Plot {
	// Get some random points
	rand.Seed(int64(0))
	n := 10
	scatterData := randomPoints(n)
	lineData := randomPoints(n)
	linePointsData := randomPoints(n)

	// Create a new plot, set its title and
	// axis labels.
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Points Example"
	p.X.Label.Text = "X"
	p.Y.Label.Text = "Y"
	// Draw a grid behind the data
	p.Add(plotter.NewGrid())

	// Make a scatter plotter and set its style.
	s, err := plotter.NewScatter(scatterData)
	if err != nil {
		panic(err)
	}
	s.GlyphStyle.Color = color.RGBA{R: 255, B: 128, A: 255}

	// Make a line plotter and set its style.
	l, err := plotter.NewLine(lineData)
	if err != nil {
		panic(err)
	}
	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}

	// Make a line plotter with points and set its style.
	lpLine, lpPoints, err := plotter.NewLinePoints(linePointsData)
	if err != nil {
		panic(err)
	}
	lpLine.Color = color.RGBA{G: 255, A: 255}
	lpPoints.Shape = plot.PyramidGlyph{}
	lpPoints.Color = color.RGBA{R: 255, A: 255}

	// Add the plotters to the plot, with a legend
	// entry for each
	p.Add(s, l, lpLine, lpPoints)
	p.Legend.Add("scatter", s)
	p.Legend.Add("line", l)
	p.Legend.Add("line points", lpLine, lpPoints)
	return p
}
开发者ID:vivounicorn,项目名称:eaburns,代码行数:53,代码来源:main.go


示例12: main

func main() {
	tests := []*Test{}
	// if file, err := os.Open("results.txt"); err != nil {
	if file, err := os.Stdin, error(nil); err != nil {
		log.Fatal(err)
	} else {
		scanner := bufio.NewScanner(file)
		for scanner.Scan() {
			test, err := ParseLine(scanner.Text())
			if err != nil {
				continue
			}
			test.Calculate()
			tests = append(tests, test)
		}
	}
	if len(tests) == 0 {
		log.Fatal("No tests found.")
	}
	if plt, err := plot.New(); err != nil {
		log.Fatal(err)
	} else {
		for i, test := range tests {
			xys := test.ToXY(100000.0)
			line, err := plotter.NewLine(xys)
			if err != nil {
				log.Fatal(err)
			}
			line.Color, line.Dashes = plotutil.Color(i), plotutil.Dashes(0)
			plt.Add(line)
			{
				name := fmt.Sprintf("%s (%d)", test.Name, int(test.Stats.Mean/100000))
				plt.Legend.Add(name, line)
			}
		}
		// plt.Legend.Font.Size = vg.Inches(plt.Legend.Font.Size * 0.75)
		plt.Legend.Font.Size *= 0.65
		plt.Legend.Top = true
		plt.Legend.Left = true
		// plt.Legend.YOffs = vg.Inches(-1.12)
		// plt.Legend.XOffs = vg.Inches(1)
		plt.HideX()
		// plt.X.Padding = 20
		plt.Y.Min = 0
		plt.Y.Max = 1600
		plt.Title.Text = fmt.Sprintf("Speed Test (averaged over %d runs and %d tests)", 100000, 100)
		plt.Y.Label.Text = "Cycles"
		plt.Save(6, 4, "number-parse.svg")
	}
}
开发者ID:norcalli,项目名称:number-parse,代码行数:50,代码来源:interpret.go


示例13: AddStackedAreaPlots

// AddStackedAreaPlots adds stacked area plot plotters to a plot.
// The variadic arguments must be either strings
// or plotter.Valuers.  Each valuer adds a stacked area
// plot to the plot below the stacked area plots added
// before it.  If a plotter.Valuer is immediately
// preceeded by a string then the string value is used to
// label the legend.
// Plots should be added in order of tallest to shortest,
// because they will be drawn in the order they are added
// (i.e. later plots will be painted over earlier plots).
//
// If an error occurs then none of the plotters are added
// to the plot, and the error is returned.
func AddStackedAreaPlots(plt *plot.Plot, xs plotter.Valuer, vs ...interface{}) error {
	var ps []plot.Plotter
	names := make(map[*plotter.Line]string)
	name := ""
	var i int

	for _, v := range vs {
		switch t := v.(type) {
		case string:
			name = t

		case plotter.Valuer:
			if xs.Len() != t.Len() {
				return errors.New("X/Y length mismatch")
			}

			// Make a line plotter and set its style.
			l, err := plotter.NewLine(combineXYs{xs: xs, ys: t})
			if err != nil {
				return err
			}

			l.LineStyle.Width = vg.Points(0)
			color := Color(i)
			i++
			l.ShadeColor = &color

			ps = append(ps, l)

			if name != "" {
				names[l] = name
				name = ""
			}

		default:
			panic(fmt.Sprintf("AddStackedAreaPlots handles strings and plotter.Valuers, got %T", t))
		}
	}

	plt.Add(ps...)
	for p, n := range names {
		plt.Legend.Add(n, p)
	}

	return nil
}
开发者ID:jen6,项目名称:plotinum,代码行数:59,代码来源:add.go


示例14: plotBehind

func plotBehind(sp *raw.SpicePlot, scale_vector *raw.SpiceVector, typemap map[string][]*raw.SpiceVector) PlotMap {
	m := findMultiplicity(scale_vector.Data)
	c := int(sp.NPoints) / m
	plots := PlotMap{}
	for vector_type, vectors := range typemap {
		plot, err := plot.New()
		if err != nil {
			log.Fatal(err)
		}
		for i, vector := range vectors {
			xys := SpiceToXY(scale_vector, vector)
			for j := 0; j < m; j++ {
				line, err := plotter.NewLine(xys[j*c : (j+1)*c])
				if err != nil {
					log.Fatal(err)
				}
				line.Color = plotutil.Color(i)
				line.Dashes = plotutil.Dashes(0)
				plot.Add(line)
				// plot.Legend.Add(vector.Name, line)
				// plot.Legend.Add(fmt.Sprintf("%s-%d", vector.Name, j), line)
				if j == 0 {
					plot.Legend.Add(vector.Name, line)
				}
			}
			// xys := SpiceToXY(scale_vector, vector)
			// line, err := plotter.NewLine(xys)
			// if err != nil {
			// 	log.Fatal(err)
			// }
			// line.Color = plotutil.Color(i + 1)
			// line.Dashes = plotutil.Dashes(0)
			// plot.Add(line)
			// plot.Legend.Add(vector.Name, line)
		}
		plot.Title.Text = sp.Title + ": " + sp.Name
		plot.X.Label.Text = scale_vector.Name
		plot.Y.Label.Text = vector_type
		// plots = append(plots, plot)
		plots[vector_type] = plot
	}
	return plots
}
开发者ID:norcalli,项目名称:spiceplot,代码行数:43,代码来源:spiceplot.go


示例15: Example_points

// Example_points draws some scatter points, a line,
// and a line with points.
func Example_points() *plot.Plot {
	rand.Seed(int64(0))

	n := 15
	scatterData := randomPoints(n)
	lineData := randomPoints(n)
	linePointsData := randomPoints(n)

	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Points Example"
	p.X.Label.Text = "X"
	p.Y.Label.Text = "Y"
	p.Add(plotter.NewGrid())

	s := must(plotter.NewScatter(scatterData)).(*plotter.Scatter)
	s.GlyphStyle.Color = color.RGBA{R: 255, B: 128, A: 255}
	s.GlyphStyle.Radius = vg.Points(3)

	l := must(plotter.NewLine(lineData)).(*plotter.Line)
	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}

	lpLine, lpPoints, err := plotter.NewLinePoints(linePointsData)
	if err != nil {
		panic(err)
	}
	lpLine.Color = color.RGBA{G: 255, A: 255}
	lpPoints.Shape = plot.CircleGlyph{}
	lpPoints.Color = color.RGBA{R: 255, A: 255}

	p.Add(s, l, lpLine, lpPoints)
	p.Legend.Add("scatter", s)
	p.Legend.Add("line", l)
	p.Legend.Add("line points", lpLine, lpPoints)

	return p
}
开发者ID:jen6,项目名称:plotinum,代码行数:43,代码来源:main.go


示例16: Report

// Report builds up a plot of the response times of the requests
// in SVG format and writes it to out
func (r *TimingsPlotReporter) Report(out io.Writer) error {
	timestamps := make([]time.Time, 0)
	timings := make([]time.Duration, 0)

	for e := r.responses.Front(); e != nil; e = e.Next() {
		r := e.Value.(*result)
		timestamps = append(timestamps, r.timestamp)
		timings = append(timings, r.timing)
	}

	p, err := plot.New()
	if err != nil {
		return err
	}
	pts := make(plotter.XYs, len(timestamps))
	for i := 0; i < len(pts); i++ {
		pts[i].X = timestamps[i].Sub(timestamps[0]).Seconds()
		pts[i].Y = timings[i].Seconds() * 1000
	}

	line, err := plotter.NewLine(pts)
	if err != nil {
		return err
	}
	line.Color = plotutil.Color(1)

	p.Add(line)
	p.X.Padding = vg.Length(3.0)
	p.X.Label.Text = "Time elapsed"
	p.Y.Padding = vg.Length(3.0)
	p.Y.Label.Text = "Latency (ms)"

	w, h := vg.Millimeters(float64(len(timestamps))), vg.Centimeters(12.0)
	canvas := vgsvg.New(w, h)
	p.Draw(plot.MakeDrawArea(canvas))

	_, err = canvas.WriteTo(out)
	return err
}
开发者ID:nodesocket,项目名称:vegeta,代码行数:41,代码来源:timings_plot_reporter.go


示例17: AddLines

// AddLines adds Line plotters to a plot.
// The variadic arguments must be either strings
// or plotter.XYers.  Each plotter.XYer is added to
// the plot using the next color and dashes
// shape via the Color and Dashes functions.
// If a plotter.XYer is immediately preceeded by
// a string then a legend entry is added to the plot
// using the string as the name.
func AddLines(plt *plot.Plot, vs ...interface{}) {
	name := ""
	var i int
	for _, v := range vs {
		switch t := v.(type) {
		case string:
			name = t

		case plotter.XYer:
			l := plotter.NewLine(t)
			l.Color = Color(i)
			l.Dashes = Dashes(i)
			i++
			plt.Add(l)
			if name != "" {
				plt.Legend.Add(name, l)
				name = ""
			}

		default:
			panic(fmt.Sprintf("AddLines handles strings and plotter.XYers, got %T", t))
		}
	}
}
开发者ID:jackielii,项目名称:go-plotinum,代码行数:32,代码来源:add.go


示例18: WriteStepsToChart

// Writes step data and position to a graph
func WriteStepsToChart(stepData <-chan int8) {

	maxNumberSteps := 1500

	leftVel := make(chartplotter.XYs, maxNumberSteps)
	rightVel := make(chartplotter.XYs, maxNumberSteps)
	leftPos := make(chartplotter.XYs, maxNumberSteps)
	rightPos := make(chartplotter.XYs, maxNumberSteps)

	var byteDataL, byteDataR int8
	stepIndex := 0
	for stepDataOpen := true; stepDataOpen; {

		byteDataL, stepDataOpen = <-stepData
		byteDataR, stepDataOpen = <-stepData

		leftVel[stepIndex].X = float64(stepIndex)
		leftVel[stepIndex].Y = float64(byteDataL) * Settings.StepSize_MM / (32.0 * 0.002)

		rightVel[stepIndex].X = float64(stepIndex)
		rightVel[stepIndex].Y = float64(byteDataR) * Settings.StepSize_MM / (32.0 * 0.002)

		leftPos[stepIndex].X = float64(stepIndex)
		if stepIndex > 0 {
			leftPos[stepIndex].Y = leftPos[stepIndex-1].Y + (leftVel[stepIndex].Y * .002)
		} else {
			leftPos[stepIndex].Y = 0
		}

		rightPos[stepIndex].X = float64(stepIndex)
		if stepIndex > 0 {
			rightPos[stepIndex].Y = rightPos[stepIndex-1].Y + (rightVel[stepIndex].Y * .002)
		} else {
			rightPos[stepIndex].Y = 0
		}

		stepIndex++
		if stepIndex >= maxNumberSteps {
			break
		}
	}

	// chop down slices if maxNumberSteps wasn't needed
	if stepIndex < maxNumberSteps {
		leftVel = leftVel[:stepIndex]
		rightVel = rightVel[:stepIndex]
		leftPos = leftPos[:stepIndex]
		rightPos = rightPos[:stepIndex]
	}

	// Create a new plot, set its title and
	// axis labels.
	p, err := chart.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Polargraph Position & Velocity"
	p.X.Label.Text = "2ms Slice"
	p.Y.Label.Text = "Position(mm) / Velocity (mm/s)"

	// Draw a grid behind the data
	p.Add(chartplotter.NewGrid())

	leftPosLine, _ := chartplotter.NewLine(leftPos)
	leftPosLine.LineStyle.Width = vg.Points(1)
	leftPosLine.LineStyle.Color = color.RGBA{B: 255, A: 255}

	rightPosLine, _ := chartplotter.NewLine(rightPos)
	rightPosLine.LineStyle.Width = vg.Points(1)
	rightPosLine.LineStyle.Color = color.RGBA{R: 255, A: 255}

	leftVelLine, _ := chartplotter.NewLine(leftVel)
	leftVelLine.LineStyle.Width = vg.Points(1)
	leftVelLine.LineStyle.Color = color.RGBA{B: 150, G: 150, A: 255}

	rightVelLine, _ := chartplotter.NewLine(rightVel)
	rightVelLine.LineStyle.Width = vg.Points(1)
	rightVelLine.LineStyle.Color = color.RGBA{R: 150, G: 150, A: 255}

	p.Add(leftPosLine, rightPosLine)
	p.Legend.Add("Left Pos", leftPosLine)
	p.Legend.Add("Right Pos", rightPosLine)

	p.Add(leftVelLine, rightVelLine)
	p.Legend.Add("Left Vel", leftVelLine)
	p.Legend.Add("Right Vel", rightVelLine)

	// Save the plot to a PNG file.
	if err := p.Save(14, 8.5, "chart.png"); err != nil {
		panic(err)
	}
}
开发者ID:jmhdz,项目名称:gocupi,代码行数:93,代码来源:chart.go


示例19: RunServer


//.........这里部分代码省略.........
		p.Y.Label.Text = "Amount"

		c_seeders := make(plotter.XYs, 0)
		c_leechers := make(plotter.XYs, 0)
		c_complete := make(plotter.XYs, 0)
		c_comments := make(plotter.XYs, 0)

		var last *fstopinfo.FSInfoHistory
		first := true
		cttotal := int32(0)

		for _, ii := range d {
			if ii.Item != nil {
				cttotal++

				if first {
					p.Title.Text = strings.TrimSpace(ii.Item.Title)
					first = false
				}

				if last != nil && last.Item != nil {
					c_seeders = append(c_seeders, struct{ X, Y float64 }{float64(cttotal), float64(ii.Item.Seeders)})
					c_leechers = append(c_leechers, struct{ X, Y float64 }{float64(cttotal), float64(ii.Item.Leechers)})
					c_complete = append(c_complete, struct{ X, Y float64 }{float64(cttotal), float64(ii.Item.Complete - last.Item.Complete)})
					c_comments = append(c_comments, struct{ X, Y float64 }{float64(cttotal), float64(ii.Item.Comments)})
				}

				last = ii
			}
		}

		w.Header().Add("Content-Type", "image/png")

		pl_seeders, err := plotter.NewLine(c_seeders)
		if err != nil {
			http.Error(w, err.Error(), 500)
			return
		}
		pl_seeders.LineStyle.Width = vg.Length(1)
		pl_seeders.LineStyle.Color = color.RGBA{R: 255, A: 255}
		p.Add(pl_seeders)
		p.Legend.Add("Seeders", pl_seeders)

		pl_leechers, err := plotter.NewLine(c_leechers)
		if err != nil {
			http.Error(w, err.Error(), 500)
			return
		}
		pl_leechers.LineStyle.Width = vg.Length(1)
		pl_leechers.LineStyle.Color = color.RGBA{G: 255, A: 255}
		p.Add(pl_leechers)
		p.Legend.Add("Leechers", pl_leechers)

		pl_complete, err := plotter.NewLine(c_complete)
		if err != nil {
			http.Error(w, err.Error(), 500)
			return
		}
		pl_complete.LineStyle.Width = vg.Length(1)
		pl_complete.LineStyle.Color = color.RGBA{B: 255, A: 255}
		p.Add(pl_complete)
		p.Legend.Add("@Complete", pl_complete)

		pl_comments, err := plotter.NewLine(c_comments)
		if err != nil {
			http.Error(w, err.Error(), 500)
开发者ID:RangelReale,项目名称:filesharetop,代码行数:67,代码来源:server.go


示例20: main

func main() {
	fmt.Println("Running...")
	start := time.Now()
	var a float64 = -1.0 //lower limit of range
	var b float64 = 1.0  //upper limit of range
	var err plotter.XYs
	err = make(plotter.XYs, nstop-nstart)
	var maxerr float64
	var interp [4]plotter.XYs

	for i := range interp {
		interp[i] = make(plotter.XYs, np+1)
	}
	var k int = 0
	for n := nstart; n < nstop; n++ {
		maxerr = 0
		err[n-nstart].X = float64(n)
		var x []float64 = make([]float64, n+1)
		var dx float64 = (b - a) / float64(n)
		for i := range x {
			x[i] = a + dx*float64(i)
		}
		dx = (b - a) / float64(np-1)
		var j int = 1
		for i := 0; i < np+1; i++ {
			tx := a + dx*float64(i)
			if tx > x[j] && j < n {
				j++
			}
			z := (tx - x[j-1]) / (x[j] - x[j-1])
			ty := F(x[j-1])*(1-z)*(1-2*z) + 4*F((x[j-1]+x[j])/2.0)*z*(1-z) + F(x[j])*z*(2*z-1)
			maxerr = math.Max(maxerr, math.Abs(ty-F(tx)))

			if k < 4 {
				if n == plotValues[k] {
					interp[k][i].X = tx
					interp[k][i].Y = ty
				}
			}
		}
		if k < 4 {
			if n == plotValues[k] {
				k++
			}
		}
		err[n-nstart].Y = math.Log(maxerr)
	}
	//Plotting
	pi, e0 := plot.New()
	if e0 != nil {
		panic(e0)
	}
	pi.Title.Text = "Maximum Error of Spline Interpolation of Runge's Function"
	pi.X.Label.Text = "N"
	pi.Y.Label.Text = "Log(Error)"

	// Make a line plotter and set its style.
	l := plotter.NewLine(err)
	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}

	pi.Add(l)

	// Save the plot to a PNG file.
	if err := pi.Save(6, 4, "runge_error.png"); err != nil {
		panic(err)
	}

	pi, e0 = plot.New()
	if e0 != nil {
		panic(e0)
	}

	pi.Title.Text = "Spline Interpolation of Runge's Function"
	pi.X.Label.Text = "N"
	pi.Y.Label.Text = "Log(Error)"
	plotutil.AddLinePoints(pi, interp[2], interp[1], interp[0])
	//Set plot bounds
	pi.X.Min = 0
	pi.X.Max = 0.5

	// Save the plot to a PNG file.
	if err := pi.Save(6, 4, "runge_interp.png"); err != nil {
		panic(err)
	}
	fmt.Println(time.Since(start))
	fmt.Println("...program terminated successfully!")
}
开发者ID:akonneker,项目名称:scicomp,代码行数:89,代码来源:hw3.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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