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