glot: github.com/Arafatk/glot Index | Files

package glot

import "github.com/Arafatk/glot"

Index

Package Files

common.go core.go function.go glot.go pointgroup.go

type Func2d Uses

type Func2d func(x float64) float64

Func2d is a 2-d function which can be plotted with gnuplot

type Func3d Uses

type Func3d func(x float64, y float64) float64

Func3d is a 3-d function which can be plotted with gnuplot

type Plot Uses

type Plot struct {
    PointGroup map[string]*PointGroup // A map between Curve name and curve type. This maps a name to a given curve in a plot. Only one curve with a given name exists in a plot.
    // contains filtered or unexported fields
}

Plot is the basic type representing a plot. Every plot has a set of Pointgroups that are simultaneously plotted on a 2/3 D plane given the plot type. The Plot dimensions must be specified at the time of construction and can't be changed later. All the Pointgroups added to a plot must have same dimensions as the dimension specified at the the time of plot construction. The Pointgroups can be dynamically added and removed from a plot And style changes can also be made dynamically.

func NewPlot Uses

func NewPlot(dimensions int, persist, debug bool) (*Plot, error)

NewPlot Function makes a new plot with the specified dimensions.

Usage

dimensions := 3
persist := false
debug := false
plot, _ := glot.NewPlot(dimensions, persist, debug)

Variable definitions

dimensions  :=> refers to the dimensions of the plot.
debug       :=> can be used by developers to check the actual commands sent to gnu plot.
persist     :=> used to make the gnu plot window stay open.

func (*Plot) AddFunc2d Uses

func (plot *Plot) AddFunc2d(name string, style string, x []float64, fct Func2d) error

AddFunc2d is used to make a 2-d plot of the format y = Function(x)

Usage

dimensions := 2
persist := false
debug := false
plot, _ := glot.NewPlot(dimensions, persist, debug)
fct := func(x float64) float64 { return (math.Exp(x)) }
groupName := "Exponential Curve"
style := "lines"
pointsX := []float64{1, 2, 3, 4, 5}
plot.AddFunc2d(groupName, style, pointsX, fct)
plot.SavePlot("1.png")

Variable definitions

dimensions  :=> refers to the dimensions of the plot.
debug       :=> can be used by developers to check the actual commands sent to gnu plot.
persist     :=> used to make the gnu plot window stay open.
groupName   :=> Name of the curve
style       :=> Style of the curve
pointsX     :=> The x Value of the points to be plotted.  y = func(x) is plotted on the curve.
style       :=> Style of the curve

NOTE: Currently only float64 type is supported for this function

func (*Plot) AddFunc3d Uses

func (plot *Plot) AddFunc3d(name string, style string, x []float64, y []float64, fct Func3d) error

AddFunc3d is used to make a 3-d plot of the format z = Function(x,y)

Usage

dimensions := 3
persist := false
debug := false
plot, _ := glot.NewPlot(dimensions, persist, debug)
fct := func(x, y float64) float64 { return x - y }
groupName := "Stright Line"
style := "lines"
pointsY := []float64{1, 2, 3, 4, 5}
pointsX := []float64{1, 2, 3, 4, 5}
plot.AddFunc3d(groupName, style, pointsX, pointsY, fct)
plot.SetXrange(0, 5)
plot.SetYrange(0, 5)
plot.SetZrange(0, 5)
plot.SavePlot("1.png")

Variable definitions

dimensions  :=> refers to the dimensions of the plot.
debug       :=> can be used by developers to check the actual commands sent to gnu plot.
persist     :=> used to make the gnu plot window stay open.
groupName   :=> Name of the curve
style       :=> Style of the curve
pointsX     :=> The x Value of the points to be plotted.  y = func(x) is plotted on the curve.

NOTE: Currently only float64 type is supported for this function

func (*Plot) AddPointGroup Uses

func (plot *Plot) AddPointGroup(name string, style string, data interface{}) (err error)

AddPointGroup function adds a group of points to a plot.

Usage

dimensions := 2
persist := false
debug := false
plot, _ := glot.NewPlot(dimensions, persist, debug)
plot.AddPointGroup("Sample1", "points", []int32{51, 8, 4, 11})
plot.AddPointGroup("Sample2", "points", []int32{1, 2, 4, 11})
plot.SavePlot("1.png")

func (*Plot) CheckedCmd Uses

func (plot *Plot) CheckedCmd(format string, a ...interface{})

CheckedCmd is a convenience wrapper around Cmd: it will panic if the error returned by Cmd isn't nil. ex:

fname := "foo.dat"
p.CheckedCmd("plot %s", fname)

func (*Plot) Close Uses

func (plot *Plot) Close() (err error)

Close makes sure all resources used by the gnuplot subprocess are reclaimed. This method is typically called when the Plotter instance is not needed anymore. That's usually done via a defer statement:

p, err := gnuplot.NewPlotter(...)
if err != nil { /* handle error */ }
defer p.Close()

func (*Plot) Cmd Uses

func (plot *Plot) Cmd(format string, a ...interface{}) error

Cmd sends a command to the gnuplot subprocess and returns an error if something bad happened in the gnuplot process. ex:

fname := "foo.dat"
err := p.Cmd("plot %s", fname)
if err != nil {
  panic(err)
}

func (*Plot) RemovePointGroup Uses

func (plot *Plot) RemovePointGroup(name string)

RemovePointGroup helps to remove a particular point group from the plot. This way you can remove a pointgroup if it's un-necessary.

Usage

dimensions := 3
persist := false
debug := false
plot, _ := glot.NewPlot(dimensions, persist, debug)
plot.AddPointGroup("Sample1", "points", []int32{51, 8, 4, 11})
plot.AddPointGroup("Sample2", "points", []int32{1, 2, 4, 11})
plot.RemovePointGroup("Sample1")

func (*Plot) ResetPlot Uses

func (plot *Plot) ResetPlot() (err error)

ResetPlot is used to reset the whole plot. This removes all the PointGroup's from the plot and makes it new. Usage

plot.ResetPlot()

func (*Plot) ResetPointGroupStyle Uses

func (plot *Plot) ResetPointGroupStyle(name string, style string) (err error)

ResetPointGroupStyle helps to reset the style of a particular point group in a plot. Using both AddPointGroup and RemovePointGroup you can add or remove point groups. And dynamically change the plots.

Usage

dimensions := 2
persist := false
debug := false
plot, _ := glot.NewPlot(dimensions, persist, debug)
plot.AddPointGroup("Sample1", "points", []int32{51, 8, 4, 11})
plot.ResetPointGroupStyle("Sample1", "points")

func (*Plot) SavePlot Uses

func (plot *Plot) SavePlot(filename string) (err error)

SavePlot function is used to save the plot at this point. The plot is dynamic and additional pointgroups can be added and removed and different versions of the same plot can be saved.

Usage

 dimensions := 3
 persist := false
 debug := false
 plot, _ := glot.NewPlot(dimensions, persist, debug)
 plot.AddPointGroup("Sample 1", "lines", []float64{2, 3, 4, 1})
 plot.SetTitle("Test Results")
	plot.SetZrange(-2,2)
 plot.SavePlot("1.jpeg")

func (*Plot) SetFormat Uses

func (plot *Plot) SetFormat(newformat string) error

SetFormat function is used to save the plot at this point. The plot is dynamic and additional pointgroups can be added and removed and different versions of the same plot can be saved.

Usage

 dimensions := 3
 persist := false
 debug := false
 plot, _ := glot.NewPlot(dimensions, persist, debug)
 plot.AddPointGroup("Sample 1", "lines", []float64{2, 3, 4, 1})
 plot.SetTitle("Test Results")
	plot.SetFormat("pdf")
 plot.SavePlot("1.pdf")

NOTE: png is default format for saving files.

func (*Plot) SetLabels Uses

func (plot *Plot) SetLabels(labels ...string) error

SetLabels Functions helps to set labels for x, y, z axis simultaneously

Usage

 dimensions := 3
 persist := false
 debug := false
 plot, _ := glot.NewPlot(dimensions, persist, debug)
 plot.AddPointGroup("Sample 1", "lines", []float64{2, 3, 4, 1})
 plot.SetTitle("Test Results")
	plot.SetLabels("X-axis","Y-Axis","Z-Axis")

func (*Plot) SetLogscale Uses

func (plot *Plot) SetLogscale(axis string, base int) error

SetLogscale changes the label for the x-axis

Usage

dimensions := 3
persist := false
debug := false
plot, _ := glot.NewPlot(dimensions, persist, debug)
plot.SetYrange(-2, 18)
plot.AddPointGroup("rates", "circle", [][]float64{{2, 4, 8, 16, 32}, {4, 7, 4, 10, 3}})
plot.SetLogscale("x", 2)

func (*Plot) SetTitle Uses

func (plot *Plot) SetTitle(title string) error

SetTitle sets the title for the plot

Usage

dimensions := 3
persist := false
debug := false
plot, _ := glot.NewPlot(dimensions, persist, debug)
plot.AddPointGroup("Sample 1", "lines", []float64{2, 3, 4, 1})
plot.SetTitle("Test Results")

func (*Plot) SetXLabel Uses

func (plot *Plot) SetXLabel(label string) error

SetXLabel changes the label for the x-axis

Usage

 dimensions := 3
 persist := false
 debug := false
 plot, _ := glot.NewPlot(dimensions, persist, debug)
 plot.AddPointGroup("Sample 1", "lines", []float64{2, 3, 4, 1})
 plot.SetTitle("Test Results")
	plot.SetXLabel("X-Axis")

func (*Plot) SetXrange Uses

func (plot *Plot) SetXrange(start int, end int) error

SetXrange changes the label for the x-axis

Usage

 dimensions := 3
 persist := false
 debug := false
 plot, _ := glot.NewPlot(dimensions, persist, debug)
 plot.AddPointGroup("Sample 1", "lines", []float64{2, 3, 4, 1})
 plot.SetTitle("Test Results")
	plot.SetXrange(-2,2)

func (*Plot) SetYLabel Uses

func (plot *Plot) SetYLabel(label string) error

SetYLabel changes the label for the y-axis

Usage

 dimensions := 3
 persist := false
 debug := false
 plot, _ := glot.NewPlot(dimensions, persist, debug)
 plot.AddPointGroup("Sample 1", "lines", []float64{2, 3, 4, 1})
 plot.SetTitle("Test Results")
	plot.SetYLabel("Y-Axis")

func (*Plot) SetYrange Uses

func (plot *Plot) SetYrange(start int, end int) error

SetYrange changes the label for the y-axis

Usage

 dimensions := 3
 persist := false
 debug := false
 plot, _ := glot.NewPlot(dimensions, persist, debug)
 plot.AddPointGroup("Sample 1", "lines", []float64{2, 3, 4, 1})
 plot.SetTitle("Test Results")
	plot.SetYrange(-2,2)

func (*Plot) SetZLabel Uses

func (plot *Plot) SetZLabel(label string) error

SetZLabel changes the label for the z-axis

Usage

 dimensions := 3
 persist := false
 debug := false
 plot, _ := glot.NewPlot(dimensions, persist, debug)
 plot.AddPointGroup("Sample 1", "lines", []float64{2, 3, 4, 1})
 plot.SetTitle("Test Results")
	plot.SetZLabel("Z-Axis")

func (*Plot) SetZrange Uses

func (plot *Plot) SetZrange(start int, end int) error

SetZrange changes the label for the z-axis

Usage

 dimensions := 3
 persist := false
 debug := false
 plot, _ := glot.NewPlot(dimensions, persist, debug)
 plot.AddPointGroup("Sample 1", "lines", []float64{2, 3, 4, 1})
 plot.SetTitle("Test Results")
	plot.SetZrange(-2,2)

type PointGroup Uses

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

A PointGroup refers to a set of points that need to plotted. It could either be a set of points or a function of co-ordinates. For Example z = Function(x,y)(3 Dimensional) or y = Function(x) (2-Dimensional)

Package glot imports 5 packages (graph) and is imported by 1 packages. Updated 2018-12-18. Refresh now. Tools for package owners.