fnplot

package module
v0.0.0-...-78ef979 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2019 License: MIT Imports: 21 Imported by: 0

README

fnplot Build Status codecov Go Report Card GoDoc

Package fnplot provides a way to plot input/output values for arbitrary functions on a 2D cartesian coordinate plot. The input/output values are converted to scalar values (arbitrary precision floating point) in a way that attempts to preserve the relative scale of the original values.

Examples

Numeric Functions

Plot the math.Sin function between 0 and 100 on the X axis.

import (
    "math"
    "github.com/matthewdale/fnplot"
)

func main() {
    err := fnplot.FnPlot{
		Fn: fnplot.NewFn(
			math.Sin,
			2000,
			fnplot.Float64Range(0, 100),
		),
		Title: "math.Sin",
		X:     &fnplot.StdAxix{},
		Y:     &fnplot.StdAxix{},
	}.Save("sin.png")

    if err != nil {
        panic(err)
    }
}
Byte Functions

Plot the md5.Sum function using a natural log X axis and scaled Y axis.

import (
    "crypto/md5"
    "github.com/matthewdale/fnplot"
)

func main() {
    err := fnplot.FnPlot{
		Fn: fnplot.NewFn(
			func(s string) [md5.Size]byte {
				return md5.Sum([]byte(s))
			},
			2000,
			fnplot.AnyString()),
		Title: "md5.Sum",
		X:     &fnplot.LnAxis{},
		Y:     &fnplot.ScaledAxis{Max: 1000},
	}.Save("md5.png")

    if err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Axis

type Axis interface {
	Point(*big.Float) float64
	SetMaxValue(*big.Float)
}

type Fn

type Fn struct {
	// contains filtered or unexported fields
}

A Fn is a plottable function that holds the function to plot, the input generators, and the inputs and outputs as scalars.

func NewFn

func NewFn(fn interface{}, samples int, gens ...Generator) Fn

func (Fn) ValuesSet

func (fn Fn) ValuesSet() *ValuesSet

type Generator

type Generator gopter.Gen

func AlphaChar

func AlphaChar() Generator

func AlphaLowerChar

func AlphaLowerChar() Generator

func AlphaNumChar

func AlphaNumChar() Generator

func AlphaString

func AlphaString() Generator

func AlphaUpperChar

func AlphaUpperChar() Generator

func AnyString

func AnyString() Generator

func Float32

func Float32() Generator

func Float32Range

func Float32Range(min, max float32) Generator

func Float64

func Float64() Generator

func Float64Range

func Float64Range(min, max float64) Generator

func Identifier

func Identifier() Generator

func NumChar

func NumChar() Generator

func NumString

func NumString() Generator

func Rune

func Rune() Generator

func RuneNoControl

func RuneNoControl() Generator

func RuneRange

func RuneRange(min, max rune) Generator

func UnicodeChar

func UnicodeChar(table *unicode.RangeTable) Generator

func UnicodeString

func UnicodeString(table *unicode.RangeTable) Generator

type LnAxis

type LnAxis struct{}

func (LnAxis) Point

func (la LnAxis) Point(p *big.Float) float64

func (*LnAxis) SetMaxValue

func (*LnAxis) SetMaxValue(*big.Float)

type LnScaledAxis

type LnScaledAxis struct {
	Max float64
	// contains filtered or unexported fields
}

func (LnScaledAxis) Point

func (lsa LnScaledAxis) Point(p *big.Float) float64

func (*LnScaledAxis) SetMaxValue

func (lsa *LnScaledAxis) SetMaxValue(v *big.Float)

type Plot

type Plot struct {
	Title string
	Fn    Fn
	X, Y  Axis
}

func (Plot) Save

func (pl Plot) Save(filename string) error

Save writes the plot as an image to the given filename. The image format is determined by the file extension.

type ScaledAxis

type ScaledAxis struct {
	Max float64
	// contains filtered or unexported fields
}

func (ScaledAxis) Point

func (sa ScaledAxis) Point(p *big.Float) float64

func (*ScaledAxis) SetMaxValue

func (sa *ScaledAxis) SetMaxValue(v *big.Float)

type StdAxix

type StdAxix struct{}

func (StdAxix) Point

func (StdAxix) Point(p *big.Float) float64

func (*StdAxix) SetMaxValue

func (*StdAxix) SetMaxValue(*big.Float)

type Values

type Values []reflect.Value

A Values is a collection of any type of value. A Values can be converted to a scalar value (a floating point number).

func NewValues

func NewValues(args ...interface{}) Values

func (Values) Scalar

func (vs Values) Scalar() (*big.Float, error)

Scalar converts a Values to an arbitrary precision floating point number. The scalar value conversion depends on the type of input value.

Individual values that are already scalar values (floats and ints) are returned as their original value.

Collections of values (slices, arrays, and maps) are unpacked into individual values. All individual values are converted to their binary representation and appended to a byte slice. When all values are appended to the byte buffer, the bytes are interpreted as a big-endian integer value.

type ValuesSet

type ValuesSet struct {
	// contains filtered or unexported fields
}

func (*ValuesSet) PointsOn

func (set *ValuesSet) PointsOn(xAxis, yAxis Axis) (plotter.XYs, error)

Jump to

Keyboard shortcuts

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