Beispiel #1
0
func histPlot() *plot.Plot {
	// Draw some random values from the standard
	// normal distribution.
	rand.Seed(int64(0))
	v := make(plotter.Values, 1000)
	for i := range v {
		v[i] = rand.NormFloat64()
	}

	// Make a plot and set its title.
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Histogram"

	// Create a histogram of our values drawn
	// from the standard normal.
	h, err := plotter.NewHist(v, 16)
	if err != nil {
		panic(err)
	}
	// Normalize the area under the histogram to
	// sum to one.
	h.Normalize(1)
	p.Add(h)

	// The normal distribution function
	norm := plotter.NewFunction(stdNorm)
	norm.Color = color.RGBA{R: 255, A: 255}
	norm.Width = vg.Points(2)
	p.Add(norm)
	return p
}
Beispiel #2
0
// An example of making a histogram.
func Example_histogram() *plot.Plot {
	rand.Seed(int64(0))
	n := 10000
	vals := make(plotter.Values, n)
	for i := 0; i < n; i++ {
		vals[i] = rand.NormFloat64()
	}

	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Histogram"
	h, err := plotter.NewHist(vals, 16)
	if err != nil {
		panic(err)
	}
	h.Normalize(1)
	p.Add(h)

	// The normal distribution function
	norm := plotter.NewFunction(stdNorm)
	norm.Color = color.RGBA{R: 255, A: 255}
	norm.Width = vg.Points(2)
	p.Add(norm)

	return p
}
// Plots the historgram using plotinum
func Histogram(r RetCalc) {
	//eb := all_paths.End_balances()
	eb := make([]float64, len(r.All_paths), len(r.All_paths))
	incs := r.RunIncomes()
	for i := range incs {
		eb[i] = incs[i]
	}
	v := make(plotter.Values, len(eb))
	for i := range v {
		v[i] = eb[i]
	}

	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	p.Title.Text = "Histogram"
	h, err := plotter.NewHist(v, 100)
	if err != nil {
		panic(err)
	}
	//h.Normalize(1)
	p.Add(h)

	if err := p.Save(4, 4, "hist.png"); err != nil {
		panic(err)
	}
	fmt.Println(h)
}
Beispiel #4
0
func Histogram(popFitness []float64, selFitness []float64, gen int) {
	popValues := make(plotter.Values, len(popFitness))
	selValues := make(plotter.Values, len(selFitness))
	for i := range popValues {
		popValues[i] = popFitness[i]

	}
	for j := range selValues {
		selValues[j] = selFitness[j]
	}

	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = fmt.Sprint("Generation ", gen)
	p.X.Label.Text = "Fitness"
	p.Y.Label.Text = "Number of individuals"

	hPop, err := plotter.NewHist(popValues, 10)
	if err != nil {
		panic(err)
	}
	//	hPop.Normalize(100)
	gray := color.RGBA{0, 0, 0, 64}
	hPop.FillColor = gray
	hSel, err := plotter.NewHist(selValues, 10)
	if err != nil {
		panic(err)
	}
	//hSel.Normalize(100)
	blue := color.RGBA{0, 61, 245, 64}
	hSel.FillColor = blue

	p.X.Min, p.X.Max = 0.0, 1.0
	p.Y.Min, p.Y.Max = 0, float64(len(popValues))
	p.Add(hPop)
	p.Add(hSel)
	if err := p.Save(8, 4, fmt.Sprintf("hist_gen_%v.svg", gen)); err != nil {
		panic(err)
	}
}
Beispiel #5
0
// createHistogram creates a histogram from given data and bin numbers
func createHistogram(data []float64, n int) {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Add(plotter.NewGrid())
	histdata := valuer{data}
	p.Add(plotter.NewHist(histdata, n))
	p.X.Label.Text = "time / ps"
	p.Y.Label.Text = "frequency"
	p.Title.Text = fmt.Sprintf("Frequency of lifetime data from lifetime.txt. %v bins.", n)

	if err := p.Save(5, 5, fmt.Sprintf("out/Histogram with %v bins.png", n)); err != nil {
		panic(err)
	}
}
// Builds a histogram from a []float64 slice :)
func HistoFromSlice(slice []float64) *plotter.Histogram {
	fmt.Println("HistoFromSlice() call - slice analytics:")
	fmt.Printf("Max: %f\n", analytics.MaxF64(slice))
	fmt.Printf("Min: %f\n", analytics.MinF64(slice))
	fmt.Printf("Avg: %f\n", analytics.AvgF64(slice))

	v := make(plotter.Values, len(slice))
	for i := range v {
		v[i] = slice[i]
	}
	h, err := plotter.NewHist(v, 150)
	if err != nil {
		panic(err)
	}
	return h
}