本文整理汇总了Golang中github.com/vdobler/chart.ScatterChart类的典型用法代码示例。如果您正苦于以下问题:Golang ScatterChart类的具体用法?Golang ScatterChart怎么用?Golang ScatterChart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ScatterChart类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: ExprGraph
func (s *Schedule) ExprGraph(t miniprofiler.Timer, unit string, res []*expr.Result) (chart.Chart, error) {
c := chart.ScatterChart{
Key: chart.Key{Pos: "itl"},
YRange: chart.Range{Label: unit},
}
c.XRange.Time = true
for ri, r := range res {
rv := r.Value.(expr.Series)
pts := make([]chart.EPoint, len(rv))
idx := 0
for k, v := range rv {
pts[idx].X = float64(k.Unix())
pts[idx].Y = v
idx++
}
slice.Sort(pts, func(i, j int) bool {
return pts[i].X < pts[j].X
})
c.AddData(r.Group.String(), pts, chart.PlotStyleLinesPoints, Autostyle(ri))
}
return &c, nil
}
开发者ID:noblehng,项目名称:bosun,代码行数:22,代码来源:chart.go
示例4: 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
示例5: 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
示例6: 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
示例7: Graph
//.........这里部分代码省略.........
if meta.Unit != "" {
m_units[q.Metric] = meta.Unit
}
if meta.Rate != "" {
switch meta.Rate {
case metadata.Gauge:
// ignore
case metadata.Rate:
q.Rate = true
case metadata.Counter:
q.Rate = true
q.RateOptions = opentsdb.RateOptions{
Counter: true,
ResetValue: 1,
}
default:
return nil, fmt.Errorf("unknown metadata rate: %s", meta.Rate)
}
}
}
queries[i] = fmt.Sprintf(`q("%v", "%v", "%v")`, q, start, end)
if !schedule.SystemConf.GetTSDBContext().Version().FilterSupport() {
if err := schedule.Search.Expand(q); err != nil {
return nil, err
}
}
}
var tr opentsdb.ResponseSet
b, _ := json.MarshalIndent(oreq, "", " ")
t.StepCustomTiming("tsdb", "query", string(b), func() {
h := schedule.SystemConf.GetTSDBHost()
if h == "" {
err = fmt.Errorf("tsdbHost not set")
return
}
tr, err = oreq.Query(h)
})
if err != nil {
return nil, err
}
cs, err := makeChart(tr, m_units)
if err != nil {
return nil, err
}
if _, present := r.Form["png"]; present {
c := chart.ScatterChart{
Title: fmt.Sprintf("%v - %v", oreq.Start, queries),
}
c.XRange.Time = true
if min, err := strconv.ParseFloat(r.FormValue("min"), 64); err == nil {
c.YRange.MinMode.Fixed = true
c.YRange.MinMode.Value = min
}
if max, err := strconv.ParseFloat(r.FormValue("max"), 64); err == nil {
c.YRange.MaxMode.Fixed = true
c.YRange.MaxMode.Value = max
}
for ri, r := range cs {
pts := make([]chart.EPoint, len(r.Data))
for idx, v := range r.Data {
pts[idx].X = v[0]
pts[idx].Y = v[1]
}
slice.Sort(pts, func(i, j int) bool {
return pts[i].X < pts[j].X
})
c.AddData(r.Name, pts, chart.PlotStyleLinesPoints, sched.Autostyle(ri))
}
w.Header().Set("Content-Type", "image/svg+xml")
white := color.RGBA{0xff, 0xff, 0xff, 0xff}
const width = 800
const height = 600
s := svg.New(w)
s.Start(width, height)
s.Rect(0, 0, width, height, "fill: #ffffff")
sgr := svgg.AddTo(s, 0, 0, width, height, "", 12, white)
c.Plot(sgr)
s.End()
return nil, nil
}
var a []annotate.Annotation
warnings := []string{}
if schedule.SystemConf.AnnotateEnabled() {
a, err = annotateBackend.GetAnnotations(&startT, &endT)
if err != nil {
warnings = append(warnings, fmt.Sprintf("unable to get annotations: %v", err))
}
}
return struct {
Queries []string
Series []*chartSeries
Annotations []annotate.Annotation
Warnings []string
}{
queries,
cs,
a,
warnings,
}, nil
}
开发者ID:nicollet,项目名称:bosun,代码行数:101,代码来源:chart.go
示例8: InitStatsHUD
func InitStatsHUD() {
plots := chart.ScatterChart{Title: "", Options: glchart.DarkStyle}
start := time.Now()
l := float64(start.UnixNano())
r := float64(start.Add(2 * time.Second).UnixNano())
plots.XRange.Fixed(l, r, 1e9)
plots.YRange.Fixed(0.1, 100, 10)
plots.XRange.TicSetting.Tics, plots.YRange.TicSetting.Tics = 1, 1
plots.XRange.TicSetting.Mirror, plots.YRange.TicSetting.Mirror = 2, 2
plots.XRange.TicSetting.Grid, plots.YRange.TicSetting.Grid = 2, 2
plots.YRange.ShowZero = true
//plots.XRange.Log = true
//plots.YRange.Log = true
plots.Key.Pos, plots.Key.Cols = "obc", 3
plots.XRange.TicSetting.Format = func(f float64) string {
t := time.Unix(int64(f)/1e9, int64(f)%1e9)
return fmt.Sprintf("%.3v", time.Since(t))
}
memhelper.GetMaxRSS()
var gpufree float64
gpupoll := gpuinfo.PollGPUMemory()
go func() {
for gpustatus := range gpupoll {
gpufree = float64(memhelper.ByteSize(gpustatus.Free()) * memhelper.MiB)
}
}()
statistics := &Statistics{}
statistics.Add(&plots, "GPU Free", "#FF9F00", func() float64 { return gpufree })
statistics.Add(&plots, "SpareRAM()", "#ff0000", func() float64 { return float64(SpareRAM() * 1e6) })
statistics.Add(&plots, "MaxRSS", "#FFE240", func() float64 { return float64(memhelper.GetMaxRSS()) })
statistics.Add(&plots, "Heap Idle", "#33ff33", func() float64 { return float64(memstats.HeapIdle) })
statistics.Add(&plots, "Alloc", "#FF6600", func() float64 { return float64(memstats.Alloc) })
statistics.Add(&plots, "Heap Alloc", "#006699", func() float64 { return float64(memstats.HeapAlloc) })
statistics.Add(&plots, "Sys", "#996699", func() float64 { return float64(memstats.Sys) })
statistics.Add(&plots, "System Free", "#3333ff", func() float64 { return float64(SystemFree()) })
statistics.Add(&plots, "nBlocks x 1e6", "#FFCC00", func() float64 { return float64(nblocks * 1e6) })
statistics.Add(&plots, "nDrawn x 1e6", "#9C8AA5", func() float64 { return float64(blocks_rendered * 1e6) })
go func() {
top := 0.
i := -1
for {
time.Sleep(250 * time.Millisecond)
max := statistics.Update()
if max > top {
top = max
}
i++
if i%4 != 0 {
continue
}
segment := float64(1e9)
if time.Since(start) > 10*time.Second {
segment = 5e9
}
if time.Since(start) > 1*time.Minute {
segment = 30e9
}
// Update axis limits
nr := float64(time.Now().Add(2 * time.Second).UnixNano())
plots.XRange.Fixed(l, nr, segment)
plots.YRange.Fixed(-1e9, top*1.1, 500e6)
}
}()
const pw, ph = 640, 480
scalex, scaley := 0.4, 0.5
chart_gfxcontext := glchart.New(pw, ph, "", 10, color.RGBA{})
StatsHUD = func() {
glh.With(glh.Matrix{gl.PROJECTION}, func() {
gl.LoadIdentity()
gl.Translated(1-scalex, scaley-1, 0)
gl.Scaled(scalex, scaley, 1)
gl.Ortho(0, pw, ph, 0, -1, 1)
gl.Translated(0, -50, 0)
glh.With(glh.Attrib{gl.ENABLE_BIT}, func() {
gl.Disable(gl.DEPTH_TEST)
glh.With(&Timer{Name: "Chart"}, func() {
plots.Plot(chart_gfxcontext)
})
})
})
//.........这里部分代码省略.........
开发者ID:pwaller,项目名称:mema,代码行数:101,代码来源:statshud.go
示例9: 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类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论