Created
September 19, 2019 14:58
-
-
Save egonelbre/e0da22bc3cf82878323a52a2abcf1240 to your computer and use it in GitHub Desktop.
Density plot example.
This file contains hidden or 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 ( | |
"io/ioutil" | |
"math/rand" | |
"github.com/loov/plot" | |
) | |
func main() { | |
var counts []int64 | |
for i := 0; i < 1000000; i++ { | |
counts = append(counts, int64(rand.NormFloat64()*100+1000)) | |
} | |
p := plot.New() | |
density := plot.NewDensity("Count", plot.Int64sToFloat64s(counts)) | |
// density.Kernel = 10 // sometimes you need to manually tweak this when the output isn't smooth enough | |
p.AddGroup( | |
plot.NewGrid(), | |
plot.NewGizmo(), | |
density, | |
plot.NewTickLabels(), | |
) | |
svg := plot.NewSVG(800, 600) | |
p.Draw(svg) | |
ioutil.WriteFile("count.svg", svg.Bytes(), 0755) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment