本文整理汇总了Golang中github.com/gonum/plot.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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)
}
}
示例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)
}
}
示例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")
}
示例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)
}
示例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)
}
}