thist

package module
Version: v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2019 License: MIT Imports: 11 Imported by: 3

README

thist - a go package for calculating online histograms with plotting to the terminal and images

Documentation Go Report Card

Example

package main

import (
        "fmt"
        "github.com/bsipos/thist"
        "math/rand"
        "time"
)

// randStream return a channel filled with endless normal random values
func randStream() chan float64 {
        c := make(chan float64)
        go func() {
                for {
                        c <- rand.NormFloat64()
                }
        }()
        return c
}

func main() {
        // create new histogram
        h := thist.NewHist(nil, "Example histogram", "auto", -1, true)
        c := randStream()

        i := 0
        for {
                // add data point to hsitogram
                h.Update(<-c)
                if i%50 == 0 {
                        // draw histogram
                        fmt.Println(h.Draw())
                        time.Sleep(time.Second)
                }
                i++
        }
}

demo video

TODO

  • Add more details on online histogram generation.
  • Add separate object for online estimation of moments.
  • Maybe add tcell as a back-end?

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoLabel

func AutoLabel(s []float64, m float64) []string

AutoLabel generates automatic labeling based on heuristics-based rounding of the values in s.

func Bar

func Bar(x, y []float64, xlab, ylab []string, title string, info []string) string

Bar plots a bar plot on the terminal. It makes use of unicode characters.

func BarSimple

func BarSimple(x, y []float64, xlab, ylab []string, title string, info []string) string

BarSimple plots a bar plot on the terminal. Does not use unicode charcters.

func ClearScreen

func ClearScreen()

ClearScreen uses control characters to clear terminal.

func ClearScreenString

func ClearScreenString() string

ClearScreen return the control characters to clear terminal.

func Plot

func Plot(x, y []float64, xlab, ylab []string, title string, info []string, symbol, negSymbol, space, top, vbar, hbar, tvbar string) string

Plot is a general plotting function for bar plots. It is used by Bar and BarSimple.

Types

type Hist

type Hist struct {
	Title     string
	BinMode   string
	MaxBins   int
	NrBins    int
	DataCount int
	DataMap   map[float64]float64
	DataMin   float64
	DataMax   float64
	DataMean  float64
	DataSd    float64
	Normalize bool
	BinStart  []float64
	BinEnd    []float64
	Counts    []float64

	MaxPrecision float64
	Precision    float64
	BinWidth     float64
	Info         string
	// contains filtered or unexported fields
}

Hist is a struct holding the parameters and internal state of a histogram object.

func NewHist

func NewHist(data []float64, title, binMode string, maxBins int, normalize bool) *Hist

NewHist initilizes a new histogram object. If data is not nil the data points are processed and the state is updated.

func (*Hist) Draw

func (h *Hist) Draw() string

Draw calls Bar to draw the hsitogram to the terminal.

func (*Hist) DrawSimple

func (h *Hist) DrawSimple() string

DrawSimple calls BarSimple to draw the hsitogram to the terminal.

func (*Hist) Dump

func (h *Hist) Dump() string

Dump prints the bins and counts to the standard output.

func (*Hist) NormCounts

func (h *Hist) NormCounts() []float64

NormCounts returns the normalised counts for each bin.

func (*Hist) SaveImage

func (h *Hist) SaveImage(f string)

SaveImage saves a histogram to an image file using gonum plot.

func (*Hist) Summary

func (h *Hist) Summary() string

Summary return a string summary of the internal state of a Hist object.

func (*Hist) Update

func (h *Hist) Update(p float64)

Update adds a new data point and updates internal state.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL