本文整理汇总了Golang中github.com/gonum/plot/vg/vgimg.PngCanvas.Translate方法的典型用法代码示例。如果您正苦于以下问题:Golang PngCanvas.Translate方法的具体用法?Golang PngCanvas.Translate怎么用?Golang PngCanvas.Translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/gonum/plot/vg/vgimg.PngCanvas
的用法示例。
在下文中一共展示了PngCanvas.Translate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WritePNG
// WritePNG renders plot to a png file of size width x height.
func (p *Plot) WritePNG(filename string, width, height vg.Length) error {
file, err := os.Create(filename)
if err != nil {
return err
}
defer file.Close()
canvas := vgimg.PngCanvas{Canvas: vgimg.New(width, height)}
canvas.Translate(-width/2, -height/2)
p.DumpTo(canvas, width, height)
canvas.WriteTo(file)
return nil
}
示例2: TestIndividualSteps
//.........这里部分代码省略.........
}
data = panel.Layers[2].Data
if data.N != 20 {
t.Errorf("Got %d data in label df.", panel.Layers[2].Data.N)
}
// StatBin produces bins
if fields := panel.Layers[3].Data.FieldNames(); !same(fields, []string{"x", "count", "ncount", "density", "ndensity"}) {
t.Errorf("Layer 3 %q has fields %v", panel.Layers[3].Name, fields)
}
data = panel.Layers[3].Data
if data.N != 11 {
t.Errorf("Got %d data in binned df.", panel.Layers[3].Data.N)
}
// 4. Wireing
panel.WireStatToGeom()
for a, s := range panel.Scales {
fmt.Printf("====== Scale %s %q ========\n", a, s.Name)
fmt.Printf("%s\n", s.String())
}
// 5. Test Construct ConstructGeoms. This shouldn't change much as
// GeomABLine doesn't reparametrize and we don't do position adjustments.
panel.ConstructGeoms()
// 6. FinalizeScales
panel.FinalizeScales()
// Only x and y are set up
if sx, ok := panel.Scales["x"]; !ok {
t.Errorf("Missing x scale")
} else {
if sx.Pos == nil {
t.Errorf("Missing Pos for x scale.")
}
if sx.DomainMin > 1.62 || sx.DomainMax < 1.95 {
t.Errorf("Bad training: %f %f", sx.DomainMin, sx.DomainMax)
}
}
fmt.Printf("%s\n", panel.Scales["x"])
fmt.Printf("%s\n", panel.Scales["y"])
// 7. Render Geoms to Grobs using scales (Step7).
panel.RenderGeoms()
fmt.Println("Layer 0, raw data")
for _, grob := range panel.Layers[0].Grobs {
fmt.Println(" ", grob.String())
}
fmt.Println("Layer 1, linear regression")
for _, grob := range panel.Layers[1].Grobs {
fmt.Println(" ", grob.String())
}
fmt.Println("Layer 2, labels")
for _, grob := range panel.Layers[2].Grobs {
fmt.Println(" ", grob.String())
}
fmt.Println("Layer 3, histogram")
for _, grob := range panel.Layers[3].Grobs {
fmt.Println(" ", grob.String())
}
// Output
pngCanvas := vgimg.PngCanvas{Canvas: vgimg.New(800, 600)}
pngCanvas.Translate(-400, -300)
vp := Viewport{
X0: 50,
Y0: 50,
Width: 700,
Height: 500,
Canvas: pngCanvas,
}
file, err := os.Create("example.png")
if err != nil {
t.Fatalf("%", err)
}
panel.Draw(vp, true, true)
if false {
fmt.Println("Layer 0, raw data")
for _, grob := range panel.Layers[0].Grobs {
grob.Draw(vp)
}
fmt.Println("Layer 1, linear regression")
for _, grob := range panel.Layers[1].Grobs {
grob.Draw(vp)
}
fmt.Println("Layer 2, labels")
for _, grob := range panel.Layers[2].Grobs {
grob.Draw(vp)
}
fmt.Println("Layer 3, histogram")
for _, grob := range panel.Layers[3].Grobs {
grob.Draw(vp)
}
}
pngCanvas.WriteTo(file)
file.Close()
}
示例3: TestGraphicGrobs
func TestGraphicGrobs(t *testing.T) {
// Output
file, err := os.Create("grobs.png")
if err != nil {
t.Fatalf("%", err)
}
pngCanvas := vgimg.PngCanvas{Canvas: vgimg.New(10*vg.Inch, 8*vg.Inch)}
vg.Initialize(pngCanvas)
pngCanvas.Translate(-5*vg.Inch, -4*vg.Inch)
dot := func(x, y float64) {
pngCanvas.Push()
pngCanvas.SetColor(BuiltinColors["red"])
pngCanvas.SetLineWidth(5)
var p vg.Path
xr := vg.Length(x) * vg.Inch
yr := vg.Length(y) * vg.Inch
p.Move(xr-5, yr-5)
p.Line(xr-5, yr+5)
p.Line(xr+5, yr+5)
p.Line(xr+5, yr-5)
p.Close()
pngCanvas.Fill(p)
pngCanvas.Pop()
}
dot(0, 0)
dot(5, 0)
dot(0, 4)
allVP := Viewport{
X0: 0,
Y0: 0,
Width: 10 * vg.Inch,
Height: 8 * vg.Inch,
Canvas: pngCanvas,
}
innerVP := allVP.Sub(0.05, 0.05, 0.9, 0.9)
bg := GrobRect{xmin: 0, ymin: 0, xmax: 1, ymax: 1, fill: BuiltinColors["gray80"]}
bg.Draw(innerVP)
cols := []string{"red", "green", "blue", "cyan", "magenta", "yellow",
"white", "gray", "black"}
// Draw points in all shapes, three sizes and all builtin colors.
points := []Grob{}
x, y := 0.1, 0.1
for shape := DotPoint; shape <= StarPoint; shape++ {
for size := 2; size < 7; size += 2 {
y = 0.05
for _, col := range cols {
g := GrobPoint{
x: x,
y: y,
size: float64(size),
shape: shape,
color: BuiltinColors[col],
}
points = append(points, g)
y += 0.035
}
x += 0.021
}
}
x, y = 0.02, 0.05
for _, col := range cols {
g := GrobText{
x: x,
y: y,
text: col,
size: 10,
color: BuiltinColors[col],
vjust: 0.5,
hjust: 0,
}
points = append(points, g)
y += 0.035
}
x, y = 0.121, 0.36
for shape := DotPoint; shape <= StarPoint; shape++ {
dy := float64(shape%2) * 0.015
g := GrobText{
x: x,
y: y + dy,
text: shape.String(),
size: 10,
color: BuiltinColors["black"],
vjust: 0.5,
hjust: 0.5,
}
points = append(points, g)
x += 3 * 0.021
}
for _, grob := range points {
grob.Draw(innerVP)
}
// Draw lines with different styles and widths.
lines := []Grob{}
x, y = 0.1, 0.45
//.........这里部分代码省略.........