Created
October 28, 2017 19:08
-
-
Save cipepser/0ede769769cc5831b540a5896bf6e868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"math/rand" | |
"os/exec" | |
"time" | |
"gonum.org/v1/plot" | |
"gonum.org/v1/plot/plotter" | |
"gonum.org/v1/plot/vg" | |
) | |
func main() { | |
rand.Seed(time.Now().UnixNano()) | |
v := make([]float64, 100000) | |
for i := range v { | |
v[i] = rand.NormFloat64() | |
} | |
// ここから下はヒストグラム表示 | |
p, err := plot.New() | |
if err != nil { | |
panic(err) | |
} | |
h, err := plotter.NewHist(plotter.Values(v), 16) | |
if err != nil { | |
panic(err) | |
} | |
h.Normalize(1) | |
p.Add(h) | |
file := "hist.png" | |
if err := p.Save(10*vg.Inch, 6*vg.Inch, file); err != nil { | |
panic(err) | |
} | |
if err = exec.Command("open", file).Run(); err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment