MCPcopy Index your code
hub / github.com/gonum/plot / ExamplePolygon_holes

Function ExamplePolygon_holes

plotter/polygon_example_test.go:25–79  ·  view source on GitHub ↗

ExamplePolygon_holes draws a polygon with holes, showing how the different built-in vg backends render polygons with holes. The output of this example is at https://github.com/gonum/plot/blob/master/plotter/testdata/polygon_holes_golden.png, https://github.com/gonum/plot/blob/master/plotter/testdata

()

Source from the content-addressed store, hash-verified

23// https://github.com/gonum/plot/blob/master/plotter/testdata/polygon_holes_golden.pdf, and
24// https://github.com/gonum/plot/blob/master/plotter/testdata/polygon_holes_golden.eps.
25func ExamplePolygon_holes() {
26 // Create an outer ring.
27 outer1 := plotter.XYs{{X: 0, Y: 0}, {X: 4, Y: 0}, {X: 4, Y: 4}, {X: 0, Y: 4}}
28
29 // Create an inner ring with the same
30 // winding order as the outer ring.
31 inner1 := plotter.XYs{{X: 0.5, Y: 0.5}, {X: 1.5, Y: 0.5}, {X: 1.5, Y: 1.5}, {X: 0.5, Y: 1.5}}
32
33 // Create an inner polygon with the opposite
34 // winding order as the outer polygon.
35 inner2 := plotter.XYs{{X: 3.5, Y: 2.5}, {X: 2.5, Y: 2.5}, {X: 2.5, Y: 3.5}, {X: 3.5, Y: 3.5}}
36
37 poly, err := plotter.NewPolygon(outer1, inner1, inner2)
38 if err != nil {
39 log.Panic(err)
40 }
41 poly.Color = color.NRGBA{B: 255, A: 255}
42
43 p := plot.New()
44 p.Title.Text = "Polygon with holes"
45 p.X.Label.Text = "X"
46 p.Y.Label.Text = "Y"
47 p.Add(poly)
48 p.Legend.Add("key", poly)
49 p.Legend.TextStyle.Font.Size = vg.Points(8)
50 p.Legend.TextStyle.Color = color.White
51 p.Legend.ThumbnailWidth = vg.Points(10)
52
53 // Here we save the image in different file formats
54 // to show how each back end handles polygon holes.
55
56 // The vgimg backend treats both internal polygons
57 // as holes by default.
58 err = p.Save(100, 100, "testdata/polygon_holes.png")
59 if err != nil {
60 log.Panic(err)
61 }
62
63 // The vgsvg, vgpdf, and vgeps backgrounds all treat
64 // the internal polygon with the opposite winding
65 // direction as a hole but do not consider the internal
66 // polygon with the same winding direction to be a hole.
67 err = p.Save(100, 100, "testdata/polygon_holes.svg")
68 if err != nil {
69 log.Panic(err)
70 }
71 err = p.Save(100, 100, "testdata/polygon_holes.pdf")
72 if err != nil {
73 log.Panic(err)
74 }
75 err = p.Save(100, 100, "testdata/polygon_holes.eps")
76 if err != nil {
77 log.Panic(err)
78 }
79}
80
81// ExamplePolygon_hexagons creates a heat map with hexagon shapes.
82// The output of this example is at

Callers

nothing calls this directly

Calls 5

NewPolygonFunction · 0.92
NewFunction · 0.92
PointsFunction · 0.92
SaveMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected