package main
import (
"math"
)
// Gaussian represents a gaussian sampled on a "virtual" grid
// of dimension NxN.
type Gaussian struct {
Width float64
N int
}
// X returns the x coordinate corresponding to column c
func (g *Gaussian) X(c int) float64 {
return float64(c) - float64(g.N/2)
}
// Y returns the y coordinate corresponding to row r
func (g *Gaussian) Y(r int) float64 {
return float64(r) - float64(g.N/2)
}
// Z returns the value correspondin
func (g *Gaussian) Z(c, r int) float64 {
rSq := g.X(c)*g.X(c) + g.Y(r)*g.Y(r)
return math.Exp(-rSq / (g.Width * g.Width))
}
// Dims returns the dimension of the "virtual" grid
func (g *Gaussian) Dims() (int, int) {
return g.N, g.N
}
func main() {
data := Gaussian{
Width: 16.0,
N: 64,
}
pal := moreland.SmoothBlueRed().Palette(255)
hm := plotter.NewHeatMap(&data, pal)
plt, _ := plot.New()
plt.Add(hm)
plt.Save(400, 400, "demo.png")
}
==========================================================
Python code:
==========================================================
from matplotlib import pyplot as plt
import numpy as np
w = 16.0
N = 64
x = np.linspace(-N/2, N/2, N)
y = np.linspace(-N/2, N/2, N)
X, Y = np.meshgrid(x, y)
Z = np.exp(-(X**2 + Y**2)/(w*w))
plt.imshow(Z, cmap="coolwarm")
plt.savefig("imshow.png")
==========================================================
Thanks in advance,
David