当前位置: 首页>>代码示例>>Golang>>正文


Golang ScatterChart.AddDataPair方法代码示例

本文整理汇总了Golang中github.com/vdobler/chart.ScatterChart.AddDataPair方法的典型用法代码示例。如果您正苦于以下问题:Golang ScatterChart.AddDataPair方法的具体用法?Golang ScatterChart.AddDataPair怎么用?Golang ScatterChart.AddDataPair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/vdobler/chart.ScatterChart的用法示例。


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

示例1: main

func main() {
	// create file storing ks and vard
	f, err := os.Create(fname + ".csv")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	ksarray := []float64{} // store ks
	vdarray := []float64{} // store VarD
	ngarray := []float64{} // store generation number

	// do evolution
	for i := 0; i < ngen; i++ {
		pop.Evolve()
		// we make 10 samples and average
		ksmean := desc.NewMean()
		vdmean := desc.NewMean()
		for j := 0; j < sampleTime; j++ {
			sample := fwd.Sample(pop.Genomes, sampleSize)
			dmatrix := fwd.GenerateDistanceMatrix(sample)
			cmatrix := covs.NewCMatrix(sampleSize, pop.Length, dmatrix)
			ks, vard := cmatrix.D()
			ksmean.Increment(ks)
			vdmean.Increment(vard)
		}
		// write to csv
		f.WriteString(fmt.Sprintf("%d,%g,%g\n", pop.NumOfGen, ksmean.GetResult(), vdmean.GetResult()))
		if (i+1)%1000 == 0 {
			fmt.Println("Generation: ", pop.NumOfGen, ksmean.GetResult(), vdmean.GetResult())
		}

		// store array for draw
		ksarray = append(ksarray, ksmean.GetResult())
		vdarray = append(vdarray, vdmean.GetResult())
		ngarray = append(ngarray, float64(pop.NumOfGen))
	}

	// draw
	svger := render.NewSVG(fname, 1, 2, 800, 200)
	pl := chart.ScatterChart{Title: "KS"}
	pl.AddDataPair("KS", ngarray, ksarray, chart.PlotStyleLines, chart.Style{Symbol: '+', SymbolColor: "#0000ff", LineStyle: chart.SolidLine})
	svger.Plot(&pl)
	pl = chart.ScatterChart{Title: "VarD"}
	pl.AddDataPair("VarD", ngarray, vdarray, chart.PlotStyleLines, chart.Style{Symbol: '+', SymbolColor: "#0000ff", LineStyle: chart.SolidLine})
	svger.Plot(&pl)
	svger.Close()

	// save population
	jf, err := os.Create(fname + ".json")
	if err != nil {
		panic(err)
	}
	defer jf.Close()
	b, err := json.Marshal(pop)
	if err != nil {
		panic(err)
	}
	jf.Write(b)
}
开发者ID:mingzhi,项目名称:gomain,代码行数:60,代码来源:hgtfwdks.go

示例2: Add

func (s *Statistics) Add(c *chart.ScatterChart, name, col string, eval func() float64) {
	xs, ys := []float64{}, []float64{}

	rgbac := color.RGBAModel.Convert(hexcolor.Hex(col))

	c.AddDataPair(name, xs, ys, chart.PlotStyleLines,
		chart.Style{LineColor: rgbac, LineWidth: 1})

	*s = append(*s, Statistic{Eval: eval})
	for i := range c.Data {
		(*s)[i].Samples = &c.Data[i].Samples
	}
}
开发者ID:pwaller,项目名称:mema,代码行数:13,代码来源:statshud.go

示例3: main

// the converge of KS equalibrium.
func main() {
	ksarray := []float64{} // store ks
	vdarray := []float64{} // store VarD
	ngarray := []float64{} // store generation number
	// do evolution
	for i := 0; i < ngen; i++ {
		pop.Evolve()
		// select 10 samples and averge
		mean := desc.NewMean()
		vmean := desc.NewMean()
		ch := make(chan dResult)
		num := 10
		for j := 0; j < num; j++ {
			sample := fwd1.Sample(pop.Genomes, sampleSize)
			go calculateD(sample, pop.Length, ch)
		}

		for j := 0; j < num; j++ {
			dr := <-ch
			mean.Increment(dr.ks)
			vmean.Increment(dr.vard)
		}

		ksarray = append(ksarray, mean.GetResult())
		vdarray = append(vdarray, vmean.GetResult())
		ngarray = append(ngarray, float64(pop.NumOfGen))
	}

	// draw
	svger := render.NewSVG(fname, 1, 2, 800, 200)
	pl := chart.ScatterChart{Title: "KS"}
	pl.AddDataPair("KS", ngarray, ksarray, chart.PlotStyleLines, chart.Style{Symbol: '+', SymbolColor: "#0000ff", LineStyle: chart.SolidLine})
	svger.Plot(&pl)
	pl = chart.ScatterChart{Title: "VarD"}
	pl.AddDataPair("VarD", ngarray, vdarray, chart.PlotStyleLines, chart.Style{Symbol: '+', SymbolColor: "#0000ff", LineStyle: chart.SolidLine})
	svger.Plot(&pl)
	svger.Close()
}
开发者ID:mingzhi,项目名称:gomain,代码行数:39,代码来源:hgtfwdcvg.go

示例4: campaign

func campaign() {

	x := []float64{0, 1, 2, 3, 4, 5, 6}
	const plotStyle = chart.PlotStyleLines
	const lineStyle = chart.SolidLine

	dumper := NewDumper("scatter", 2, 1, 450, 400)
	defer dumper.Close()

	TTFBLow := []float64{40, 55, 40, 55, 122, 145, 166}

	// Categorized Bar Chart
	c := chart.ScatterChart{}
	c.YRange.Label = "Pro-EU"
	c.XRange.Label = "Succesfuld karriere"
	c.XRange.Category = months

	// Et klogt dyr bider ej hånden som føder den.
	// Magt fører mere magt med sig. Stå i opposition til magten, og magten har ej brug for dig.

	c.AddDataPair("Politiker", x, TTFBLow, plotStyle, chart.Style{LineColor: turquise, LineStyle: chart.LongDashLine})

	dumper.Plot(&c)
	// Du tjener systemet. Systemet belønner dig. Skønt tusind år forgår, forbliver menneskelig natur altid den samme.
	// //Det er lettere at gå i medvind, en at gå imod vinden og den herskende ånd.
	// Den der går imod vinden, går fattig, udskældt og ene.
	TTFBFileHigh20 := []float64{160, 135, 177, 130, 150, 250, 260}

	// Categorized Bar Chart
	c = chart.ScatterChart{}
	c.YRange.Label = "Idealisme"
	c.XRange.Label = "Karrierens længde"
	c.XRange.Category = months

	c.AddDataPair("Arbejdsløs", x, TTFBFileHigh20, plotStyle, chart.Style{Symbol: '#', LineColor: red, LineStyle: lineStyle})

	dumper.Plot(&c)
}
开发者ID:cinnabardk,项目名称:svg,代码行数:38,代码来源:main.go

示例5: main


//.........这里部分代码省略.........

	stepNum := etime / stepSize
	for i := 0; i < stepNum; i++ {
		// simulate
		pop.Evolve(stepSize)

		// create distance matrix
		dmatrix := pop.DistanceMatrix(sampleSize)
		c := covs.NewCMatrix(dmatrix, sampleSize, pop.Length)

		// calculate ks
		ks := c.CalculateKS()
		vard := c.CalculateVarD()
		ksfile.WriteString(fmt.Sprintf("%d\t%g\t%g\n", pop.Time, ks, vard))
		ksMean.Increment(ks)
		ksVar.Increment(ks)
		vardMean.Increment(vard)
		vardVar.Increment(vard)
		log.Printf("KsMean: %g, KsVar: %g, VardMean: %g, VardVar: %g\n", ksMean.GetResult(), ksVar.GetResult(), vardMean.GetResult(), vardVar.GetResult())

		// calculate covs
		scovs, rcovs, xyPL, xsysPL, smXYPL := c.CalculateCovs(maxL)
		for j := 0; j < maxL; j++ {
			scovsMeanArray[j].Increment(scovs[j])
			scovsVarArray[j].Increment(scovs[j])

			rcovsMeanArray[j].Increment(rcovs[j])
			rcovsVarArray[j].Increment(rcovs[j])

			xyPLMeanArray[j].Increment(xyPL[j])
			xyPLVarArray[j].Increment(xyPL[j])

			xsysPLMeanArray[j].Increment(xsysPL[j])
			xsysPLVarArray[j].Increment(xsysPL[j])

			smXYPLMeanArray[j].Increment(smXYPL[j])
			smXYPLVarArray[j].Increment(smXYPL[j])
		}

		svger := render.NewSVG(dir+"/"+prex+"_covs", 1, 5, 800, 200)
		scovMeans := make([]float64, maxL-1)
		rcovMeans := make([]float64, maxL-1)
		xyPLMeans := make([]float64, maxL-1)
		xsysPLMeans := make([]float64, maxL-1)
		smXYPLMeans := make([]float64, maxL-1)
		xs := make([]float64, maxL-1)
		for j := 1; j < maxL; j++ {
			xs[j-1] = float64(j)
			scovMeans[j-1] = scovsMeanArray[j].GetResult()
			rcovMeans[j-1] = rcovsMeanArray[j].GetResult()
			xyPLMeans[j-1] = xyPLMeanArray[j].GetResult()
			xsysPLMeans[j-1] = xsysPLMeanArray[j].GetResult()
			smXYPLMeans[j-1] = smXYPLMeanArray[j].GetResult()
		}
		pl := chart.ScatterChart{Title: "scovs"}
		pl.AddDataPair("struc covs", xs, scovMeans, chart.PlotStyleLines, chart.Style{Symbol: '+', SymbolColor: "#0000ff", LineStyle: chart.SolidLine})
		svger.Plot(&pl)

		pl = chart.ScatterChart{Title: "rcovs"}
		pl.AddDataPair("rate covs", xs, rcovMeans, chart.PlotStyleLines, chart.Style{Symbol: '+', SymbolColor: "#0000ff", LineStyle: chart.SolidLine})
		svger.Plot(&pl)

		pl = chart.ScatterChart{Title: "xyPL"}
		pl.AddDataPair("xyPL", xs, xyPLMeans, chart.PlotStyleLines, chart.Style{Symbol: '+', SymbolColor: "#0000ff", LineStyle: chart.SolidLine})
		svger.Plot(&pl)

		pl = chart.ScatterChart{Title: "xsysPL"}
		pl.AddDataPair("xsysPL", xs, xsysPLMeans, chart.PlotStyleLines, chart.Style{Symbol: '+', SymbolColor: "#0000ff", LineStyle: chart.SolidLine})
		svger.Plot(&pl)

		pl = chart.ScatterChart{Title: "smXYPL"}
		pl.AddDataPair("smXYPL", xs, smXYPLMeans, chart.PlotStyleLines, chart.Style{Symbol: '+', SymbolColor: "#0000ff", LineStyle: chart.SolidLine})
		svger.Plot(&pl)

		svger.Close()

		// write to file
		covsfilestr := dir + "/" + prex + "_covs.txt"
		covsfile, err := os.Create(covsfilestr)
		if err != nil {
			log.Fatalf("Can not create file: %s, %v", covsfilestr, err)
		}
		for j := 0; j < maxL; j++ {
			covsfile.WriteString(
				fmt.Sprintf("%d\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n",
					j,
					scovsMeanArray[j].GetResult(), scovsVarArray[j].GetResult(),
					rcovsMeanArray[j].GetResult(), rcovsVarArray[j].GetResult(),
					xyPLMeanArray[j].GetResult(), xyPLVarArray[j].GetResult(),
					xsysPLMeanArray[j].GetResult(), xsysPLVarArray[j].GetResult(),
					smXYPLMeanArray[j].GetResult(), smXYPLVarArray[j].GetResult(),
				),
			)
		}
		covsfile.Close()
	}

	tnow = time.Now()
	log.Printf("Done at %v\n", tnow)
}
开发者ID:mingzhi,项目名称:gomain,代码行数:101,代码来源:fwd_main.go

示例6: Scatter

func Scatter() {
	x := []float64{0, 1, 2, 3, 4, 5, 6}
	const plotStyle = chart.PlotStyleLines
	const lineStyle = chart.SolidLine

	dumper := NewDumper("scatter", 2, 1, 450, 400)
	defer dumper.Close()

	ping := []float64{1, 3, 5, 9, 22, 1, 56}
	TTFBLow := []float64{40, 55, 40, 55, 122, 145, 166}
	TTFBMed := []float64{89, 77, 102, 95, 232, 333, 254}
	TTFBFile := []float64{133, 55, 77, 20, 99, 102, 69}

	// Categorized Bar Chart
	c := chart.ScatterChart{}
	c.XRange.Label = "Måned"
	c.YRange.Label = "MS"
	c.XRange.Category = months

	c.AddDataPair("TTFB-Med", x, TTFBMed, plotStyle, chart.Style{LineColor: green, LineStyle: lineStyle})
	c.AddDataPair("TTFB-Low", x, TTFBLow, plotStyle, chart.Style{LineColor: turquise, LineStyle: chart.LongDashLine})
	c.AddDataPair("TTFB-File", x, TTFBFile, plotStyle, chart.Style{LineColor: yellow, LineStyle: chart.LongDashLine})
	c.AddDataPair("Ping", x, ping, plotStyle, chart.Style{LineColor: brown, LineStyle: lineStyle})

	dumper.Plot(&c)

	TTFBHigh20 := []float64{200, 300, 900, 1500, 1600, 1300}
	TTFBHigh20HotHour := []float64{250, 350, 1150, 1900, 1800, 1500}

	TTFBFileHigh20 := []float64{160, 135, 177, 130, 150, 250, 260}
	TTFBFileHigh20HotHour := []float64{360, 235, 277, 190, 180, 270, 290}

	// Categorized Bar Chart
	c = chart.ScatterChart{}
	c.XRange.Label = "Måned"
	c.YRange.Label = "MS"
	c.XRange.Category = months

	c.AddDataPair("TTFB-High", x, TTFBHigh20, plotStyle, chart.Style{Symbol: '#', LineColor: green, LineStyle: lineStyle})
	c.AddDataPair("  - kl. 17-21", x, TTFBHigh20HotHour, plotStyle, chart.Style{
		Symbol: '#', LineColor: violet, LineStyle: chart.LongDashLine})

	c.AddDataPair("TTFB-FileHigh", x, TTFBFileHigh20, plotStyle, chart.Style{Symbol: '#', LineColor: red, LineStyle: lineStyle})
	c.AddDataPair("  - kl. 17-21", x, TTFBFileHigh20HotHour, plotStyle, chart.Style{Symbol: '#', LineColor: blue, LineStyle: chart.LongDashLine})

	dumper.Plot(&c)
}
开发者ID:cinnabardk,项目名称:svg,代码行数:47,代码来源:main.go


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