Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions align.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func Align(plots [][]*Plot, t draw.Tiles, dc draw.Canvas) [][]draw.Canvas {
}

// Create the initial tiles.
for j := 0; j < t.Rows; j++ {
for j := range t.Rows {
if len(plots[j]) != t.Cols {
panic(fmt.Errorf("plot: plots row %d columns (%d) != tiles columns (%d)", j, len(plots[j]), t.Rows))
}

o[j] = make([]draw.Canvas, len(plots[j]))
for i := 0; i < t.Cols; i++ {
for i := range t.Cols {
o[j][i] = t.At(dc, i, j)
}
}
Expand Down
8 changes: 4 additions & 4 deletions align_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
func ExampleAlign() {
const rows, cols = 4, 3
plots := make([][]*plot.Plot, rows)
for j := 0; j < rows; j++ {
for j := range rows {
plots[j] = make([]*plot.Plot, cols)
for i := 0; i < cols; i++ {
for i := range cols {
if i == 0 && j == 2 {
// This shows what happens when there are nil plots.
continue
Expand Down Expand Up @@ -70,8 +70,8 @@ func ExampleAlign() {
}

canvases := plot.Align(plots, t, dc)
for j := 0; j < rows; j++ {
for i := 0; i < cols; i++ {
for j := range rows {
for i := range cols {
if plots[j][i] != nil {
plots[j][i].Draw(canvases[j][i])
}
Expand Down
2 changes: 1 addition & 1 deletion palette/brewer/brewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func GetPalette(typ PaletteType, name string, colors int) (palette.Palette, erro
)
switch typ {
case TypeAny:
var pt interface{}
var pt any
pt, nameOk = all[name]
if !nameOk {
break
Expand Down
2 changes: 1 addition & 1 deletion palette/brewer/palettes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4752,7 +4752,7 @@ var (
"YlOrBr": YlOrBr,
"YlOrRd": YlOrRd,
}
all = map[string]interface{}{
all = map[string]any{
"BrBG": BrBG,
"PiYG": PiYG,
"PRGn": PRGn,
Expand Down
4 changes: 2 additions & 2 deletions palette/moreland/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func Example() {
YOffset: -50,
Data: mat.NewDense(100, 100, nil),
}
for i := 0; i < 100; i++ {
for j := 0; j < 100; j++ {
for i := range 100 {
for j := range 100 {
x := float64(i-50) / 10
y := float64(j-50) / 10
v := math.Sin(x*x+y*y) / (x*x + y*y)
Expand Down
2 changes: 1 addition & 1 deletion palette/moreland/luminance.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (l luminance) Palette(n int) palette.Palette {
delta := (l.max - l.min) / float64(n-1)
var v float64
c := make([]color.Color, n)
for i := 0; i < n; i++ {
for i := range n {
v = l.min + float64(delta*float64(i))
var err error
c[i], err = l.At(v)
Expand Down
2 changes: 1 addition & 1 deletion plotter/barchart_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func ExampleBarChart_positiveNegative() {
data1 := make(plotter.Values, n)
data2 := make(plotter.Values, n)
net := make(plotter.XYs, n) // net = data1 + data2
for i := 0; i < n; i++ {
for i := range n {
data1[i] = rnd.Float64()*2 - 1
data2[i] = rnd.Float64()*2 - 1
net[i].X = data1[i] + data2[i]
Expand Down
2 changes: 1 addition & 1 deletion plotter/boxplot_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ExampleBoxPlot() {
uniform := make(plotter.ValueLabels, n)
normal := make(plotter.ValueLabels, n)
expon := make(plotter.ValueLabels, n)
for i := 0; i < n; i++ {
for i := range n {
uniform[i].Value = rnd.Float64()
uniform[i].Label = fmt.Sprintf("%4.4f", uniform[i].Value)
normal[i].Value = rnd.NormFloat64()
Expand Down
4 changes: 2 additions & 2 deletions plotter/colorbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (l *ColorBar) Plot(c draw.Canvas, p *plot.Plot) {
Min: image.Point{X: 0, Y: 0},
Max: image.Point{X: 1, Y: colors},
})
for i := 0; i < colors; i++ {
for i := range colors {
color, err := l.ColorMap.At(l.ColorMap.Min() + delta*float64(i))
if err != nil {
panic(err)
Expand All @@ -75,7 +75,7 @@ func (l *ColorBar) Plot(c draw.Canvas, p *plot.Plot) {
Min: image.Point{X: 0, Y: 0},
Max: image.Point{X: colors, Y: 1},
})
for i := 0; i < colors; i++ {
for i := range colors {
color, err := l.ColorMap.At(l.ColorMap.Min() + delta*float64(i))
if err != nil {
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions plotter/conrec.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func conrec(g GridXYZ, heights []float64, fn conrecLine) {
)

c, r := g.Dims()
for i := 0; i < c-1; i++ {
for j := 0; j < r-1; j++ {
for i := range c - 1 {
for j := range r - 1 {
dmin := math.Min(
math.Min(g.Z(i, j), g.Z(i, j+1)),
math.Min(g.Z(i+1, j), g.Z(i+1, j+1)),
Expand All @@ -92,7 +92,7 @@ func conrec(g GridXYZ, heights []float64, fn conrecLine) {
continue
}

for k := 0; k < len(heights); k++ {
for k := range heights {
if heights[k] < dmin || dmax < heights[k] {
continue
}
Expand Down
15 changes: 8 additions & 7 deletions plotter/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package plotter
import (
"image/color"
"math"
"slices"
"sort"

"gonum.org/v1/plot"
Expand Down Expand Up @@ -64,8 +65,8 @@ func NewContour(g GridXYZ, levels []float64, p palette.Palette) *Contour {
default:
min, max = math.Inf(1), math.Inf(-1)
c, r := g.Dims()
for i := 0; i < c; i++ {
for j := 0; j < r; j++ {
for i := range c {
for j := range r {
v := g.Z(i, j)
if math.IsNaN(v) {
continue
Expand Down Expand Up @@ -98,8 +99,8 @@ var defaultQuantiles = []float64{0.01, 0.05, 0.25, 0.5, 0.75, 0.95, 0.99}
func quantilesR7(g GridXYZ, p []float64) []float64 {
c, r := g.Dims()
data := make([]float64, 0, c*r)
for i := 0; i < c; i++ {
for j := 0; j < r; j++ {
for i := range c {
for j := range r {
if v := g.Z(i, j); !math.IsNaN(v) {
data = append(data, v)
}
Expand Down Expand Up @@ -267,8 +268,8 @@ func (h *Contour) DataRange() (xmin, xmax, ymin, ymax float64) {
func (h *Contour) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox {
c, r := h.GridXYZ.Dims()
b := make([]plot.GlyphBox, 0, r*c)
for i := 0; i < c; i++ {
for j := 0; j < r; j++ {
for i := range c {
for j := range r {
b = append(b, plot.GlyphBox{
X: plt.X.Norm(h.GridXYZ.X(i)),
Y: plt.Y.Norm(h.GridXYZ.Y(j)),
Expand Down Expand Up @@ -651,7 +652,7 @@ func (c *contour) exciseQuick(conts contourSet) {
conts[&contour{
z: c.z,
backward: path{wp[i]},
forward: append(path(nil), wp[i+1:j+1]...),
forward: slices.Clone(wp[i+1 : j+1]),
}] = struct{}{}
wp = append(wp[:i], wp[j:]...)
j = i + 1
Expand Down
5 changes: 3 additions & 2 deletions plotter/contour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"math"
"reflect"
"slices"
"sort"
"testing"

Expand Down Expand Up @@ -457,8 +458,8 @@ func TestExciseLoops(t *testing.T) {
for i, test := range loopTests {
gotSet := make(contourSet)
c := &contour{
backward: append(path(nil), test.c.backward...),
forward: append(path(nil), test.c.forward...),
backward: slices.Clone(test.c.backward),
forward: slices.Clone(test.c.forward),
}
gotSet[c] = struct{}{}
c.exciseLoops(gotSet, quick)
Expand Down
12 changes: 6 additions & 6 deletions plotter/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ type Field struct {
func NewField(f FieldXY) *Field {
max := math.Inf(-1)
c, r := f.Dims()
for i := 0; i < c; i++ {
for j := 0; j < r; j++ {
for i := range c {
for j := range r {
v := f.Vector(i, j)
d := math.Hypot(v.X, v.Y)
if math.IsNaN(d) {
Expand All @@ -93,7 +93,7 @@ func (f *Field) Plot(c draw.Canvas, plt *plot.Plot) {
trX, trY := plt.Transforms(&c)

cols, rows := f.FieldXY.Dims()
for i := 0; i < cols; i++ {
for i := range cols {
var right, left float64
switch i {
case 0:
Expand All @@ -111,7 +111,7 @@ func (f *Field) Plot(c draw.Canvas, plt *plot.Plot) {
left = -(f.FieldXY.X(i) - f.FieldXY.X(i-1)) / 2
}

for j := 0; j < rows; j++ {
for j := range rows {
var up, down float64
switch j {
case 0:
Expand Down Expand Up @@ -200,8 +200,8 @@ func (f *Field) DataRange() (xmin, xmax, ymin, ymax float64) {
func (f *Field) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox {
c, r := f.FieldXY.Dims()
b := make([]plot.GlyphBox, 0, r*c)
for i := 0; i < c; i++ {
for j := 0; j < r; j++ {
for i := range c {
for j := range r {
b = append(b, plot.GlyphBox{
X: plt.X.Norm(f.FieldXY.X(i)),
Y: plt.Y.Norm(f.FieldXY.Y(j)),
Expand Down
16 changes: 8 additions & 8 deletions plotter/heat.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func NewHeatMap(g GridXYZ, p palette.Palette) *HeatMap {
default:
min, max = math.Inf(1), math.Inf(-1)
c, r := g.Dims()
for i := 0; i < c; i++ {
for j := 0; j < r; j++ {
for i := range c {
for j := range r {
v := g.Z(i, j)
if math.IsNaN(v) {
continue
Expand Down Expand Up @@ -120,8 +120,8 @@ func (h *HeatMap) plotRasterized(c draw.Canvas, plt *plot.Plot) {

pal := h.Palette.Colors()
ps := float64(len(pal)-1) / (h.Max - h.Min)
for i := 0; i < cols; i++ {
for j := 0; j < rows; j++ {
for i := range cols {
for j := range rows {
var col color.Color
switch v := h.GridXYZ.Z(i, j); {
case v < h.Min:
Expand Down Expand Up @@ -161,7 +161,7 @@ func (h *HeatMap) plotVectorized(c draw.Canvas, plt *plot.Plot) {

var pa vg.Path
cols, rows := h.GridXYZ.Dims()
for i := 0; i < cols; i++ {
for i := range cols {
var right, left float64
switch i {
case 0:
Expand All @@ -179,7 +179,7 @@ func (h *HeatMap) plotVectorized(c draw.Canvas, plt *plot.Plot) {
left = -(h.GridXYZ.X(i) - h.GridXYZ.X(i-1)) / 2
}

for j := 0; j < rows; j++ {
for j := range rows {
var up, down float64
switch j {
case 0:
Expand Down Expand Up @@ -258,8 +258,8 @@ func (h *HeatMap) DataRange() (xmin, xmax, ymin, ymax float64) {
func (h *HeatMap) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox {
c, r := h.GridXYZ.Dims()
b := make([]plot.GlyphBox, 0, r*c)
for i := 0; i < c; i++ {
for j := 0; j < r; j++ {
for i := range c {
for j := range r {
b = append(b, plot.GlyphBox{
X: plt.X.Norm(h.GridXYZ.X(i)),
Y: plt.Y.Norm(h.GridXYZ.Y(j)),
Expand Down
4 changes: 2 additions & 2 deletions plotter/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func binPoints(xys XYer, n int) (bins []HistogramBin, width float64) {
xmin, xmax := Range(XValues{xys})
if n <= 0 {
m := 0.0
for i := 0; i < xys.Len(); i++ {
for i := range xys.Len() {
_, y := xys.XY(i)
m += math.Max(y, 1.0)
}
Expand All @@ -207,7 +207,7 @@ func binPoints(xys XYer, n int) (bins []HistogramBin, width float64) {
bins[i].Max = xmin + float64(i+1)*w
}

for i := 0; i < xys.Len(); i++ {
for i := range xys.Len() {
x, y := xys.XY(i)
bin := int((x - xmin) / w)
if x == xmax {
Expand Down
2 changes: 1 addition & 1 deletion plotter/histogram_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ExampleHistogram() {

n := 10000
vals := make(plotter.Values, n)
for i := 0; i < n; i++ {
for i := range n {
vals[i] = rnd.NormFloat64()
}

Expand Down
4 changes: 2 additions & 2 deletions plotter/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ func (img *Image) transformFor(p *plot.Plot) image.Image {
}
b := img.img.Bounds()
o := image.NewNRGBA64(b)
for c := 0; c < img.cols; c++ {
for c := range img.cols {
// Find the equivalent image column after applying axis transforms.
cTrans := int(p.X.Norm(img.x(c)) * float64(img.cols))
// Find the equivalent column of the previous image column after applying
// axis transforms.
cPrevTrans := int(p.X.Norm(img.x(maxInt(c-1, 0))) * float64(img.cols))
for r := 0; r < img.rows; r++ {
for r := range img.rows {
// Find the equivalent image row after applying axis transforms.
rTrans := int(p.Y.Norm(img.y(r)) * float64(img.rows))
// Find the equivalent row of the previous image row after applying
Expand Down
4 changes: 2 additions & 2 deletions plotter/plotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Valuer interface {
func Range(vs Valuer) (min, max float64) {
min = math.Inf(1)
max = math.Inf(-1)
for i := 0; i < vs.Len(); i++ {
for i := range vs.Len() {
v := vs.Value(i)
min = math.Min(min, v)
max = math.Max(max, v)
Expand Down Expand Up @@ -93,7 +93,7 @@ func CopyValues(vs Valuer) (Values, error) {
return nil, ErrNoData
}
cpy := make(Values, vs.Len())
for i := 0; i < vs.Len(); i++ {
for i := range vs.Len() {
cpy[i] = vs.Value(i)
if err := CheckFloats(cpy[i]); err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions plotter/polygon_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ func ExamplePolygon_hexagons() {
for i, xmin := range xstart {
ymin := ystart[i]
x := xmin
for ix := 0; ix < nx; ix++ {
for range nx {
y := ymin
for iy := 0; iy < ny; iy++ {
for range ny {
var poly *plotter.Polygon
poly, err = plotter.NewPolygon(hex(x, y, r))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion plotter/quartile_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func ExampleQuartPlot() {
uniform := make(plotter.Values, n)
normal := make(plotter.Values, n)
expon := make(plotter.Values, n)
for i := 0; i < n; i++ {
for i := range n {
uniform[i] = rnd.Float64()
normal[i] = rnd.NormFloat64()
expon[i] = rnd.ExpFloat64()
Expand Down
2 changes: 1 addition & 1 deletion plotter/rotation_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Example_rotation() {
// Sin creates a sine curve.
sin := func(n int, xmax float64) plotter.XYs {
xy := make(plotter.XYs, n)
for i := 0; i < n; i++ {
for i := range n {
xy[i].X = xmax / float64(n) * float64(i)
xy[i].Y = math.Sin(xy[i].X) * 100
}
Expand Down
Loading
Loading