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

Function ExampleHeatMap

plotter/heat_example_test.go:21–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19)
20
21func ExampleHeatMap() {
22 m := offsetUnitGrid{
23 XOffset: -2,
24 YOffset: -1,
25 Data: mat.NewDense(3, 4, []float64{
26 1, 2, 3, 4,
27 5, 6, 7, 8,
28 9, 10, 11, 12,
29 })}
30 pal := palette.Heat(12, 1)
31 h := plotter.NewHeatMap(m, pal)
32
33 p := plot.New()
34 p.Title.Text = "Heat map"
35
36 p.X.Tick.Marker = integerTicks{}
37 p.Y.Tick.Marker = integerTicks{}
38
39 p.Add(h)
40
41 // Create a legend.
42 l := plot.NewLegend()
43 thumbs := plotter.PaletteThumbnailers(pal)
44 for i := len(thumbs) - 1; i >= 0; i-- {
45 t := thumbs[i]
46 if i != 0 && i != len(thumbs)-1 {
47 l.Add("", t)
48 continue
49 }
50 var val float64
51 switch i {
52 case 0:
53 val = h.Min
54 case len(thumbs) - 1:
55 val = h.Max
56 }
57 l.Add(fmt.Sprintf("%.2g", val), t)
58 }
59
60 p.X.Padding = 0
61 p.Y.Padding = 0
62 p.X.Max = 1.5
63 p.Y.Max = 1.5
64
65 img := vgimg.New(250, 175)
66 dc := draw.New(img)
67
68 l.Top = true
69 // Calculate the width of the legend.
70 r := l.Rectangle(dc)
71 legendWidth := r.Max.X - r.Min.X
72 l.YOffs = -p.Title.TextStyle.FontExtents().Height // Adjust the legend down a little.
73
74 l.Draw(dc)
75 dc = draw.Crop(dc, 0, -legendWidth-vg.Millimeter, 0, 0) // Make space for the legend.
76 p.Draw(dc)
77 w, err := os.Create("testdata/heatMap.png")
78 if err != nil {

Callers

nothing calls this directly

Calls 15

AddMethod · 0.95
RectangleMethod · 0.95
DrawMethod · 0.95
WriteToMethod · 0.95
HeatFunction · 0.92
NewHeatMapFunction · 0.92
NewFunction · 0.92
NewLegendFunction · 0.92
PaletteThumbnailersFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
CropFunction · 0.92

Tested by

no test coverage detected