NewContour creates as new contour plotter for the given data, using the provided palette. If levels is nil, contours are generated for the 0.01, 0.05, 0.25, 0.5, 0.75, 0.95 and 0.99 quantiles. If g has Min and Max methods that return a float, those returned values are used to set the respective Cont
(g GridXYZ, levels []float64, p palette.Palette)
| 54 | // If the returned Contour is used when Min is greater than Max, the |
| 55 | // Plot method will panic. |
| 56 | func NewContour(g GridXYZ, levels []float64, p palette.Palette) *Contour { |
| 57 | var min, max float64 |
| 58 | type minMaxer interface { |
| 59 | Min() float64 |
| 60 | Max() float64 |
| 61 | } |
| 62 | switch g := g.(type) { |
| 63 | case minMaxer: |
| 64 | min, max = g.Min(), g.Max() |
| 65 | default: |
| 66 | min, max = math.Inf(1), math.Inf(-1) |
| 67 | c, r := g.Dims() |
| 68 | for i := range c { |
| 69 | for j := range r { |
| 70 | v := g.Z(i, j) |
| 71 | if math.IsNaN(v) { |
| 72 | continue |
| 73 | } |
| 74 | min = math.Min(min, v) |
| 75 | max = math.Max(max, v) |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if len(levels) == 0 { |
| 81 | levels = quantilesR7(g, defaultQuantiles) |
| 82 | } |
| 83 | |
| 84 | return &Contour{ |
| 85 | GridXYZ: g, |
| 86 | Levels: levels, |
| 87 | LineStyles: []draw.LineStyle{DefaultLineStyle}, |
| 88 | Palette: p, |
| 89 | Min: min, |
| 90 | Max: max, |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // Default quantiles for case where levels is not explicitly set. |
| 95 | var defaultQuantiles = []float64{0.01, 0.05, 0.25, 0.5, 0.75, 0.95, 0.99} |