Skip to content

Instantly share code, notes, and snippets.

@egonelbre
Created September 19, 2019 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egonelbre/e0da22bc3cf82878323a52a2abcf1240 to your computer and use it in GitHub Desktop.
Save egonelbre/e0da22bc3cf82878323a52a2abcf1240 to your computer and use it in GitHub Desktop.
Density plot example.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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