Documentation ¶
Overview ¶
gnuplot is a simple minded set of functions to manage a gnuplot subprocess in order to plot data. See the gnuplot documentation page for the exact semantics of the gnuplot commands.
http://www.gnuplot.info/
Index ¶
- type Func
- type Plotter
- func (self *Plotter) CheckedCmd(format string, a ...interface{})
- func (self *Plotter) Close() (err error)
- func (self *Plotter) Cmd(format string, a ...interface{}) error
- func (self *Plotter) PlotFunc(data []float64, fct Func, title string, nr int) error
- func (self *Plotter) PlotNd(extra string, data ...[]float64) error
- func (self *Plotter) PlotX(data []float64, extra string) error
- func (self *Plotter) PlotXY(x, y []float64, extra string) error
- func (self *Plotter) PlotXYZ(x, y, z []float64, extra string) error
- func (self *Plotter) ResetPlot() (err error)
- func (self *Plotter) SetLabels(labels ...string) error
- func (self *Plotter) SetPlotCmd(cmd string) (err error)
- func (self *Plotter) SetStyle(style string)
- func (self *Plotter) SetXLabel(label string) error
- func (self *Plotter) SetYLabel(label string) error
- func (self *Plotter) SetZLabel(label string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Plotter ¶
type Plotter struct {
// contains filtered or unexported fields
}
Plotter is a handle to a gnuplot subprocess, forwarding commands via its stdin
func NewPlotter ¶
NewPlotter creates a new Plotter instance.
- `fname` is the name of the file containing commands (should be empty for now)
- `persist` is a flag to run the gnuplot subprocess with '-persist' so the plot window isn't closed after sending a command
- `debug` is a flag to tell go-gnuplot to print out every command sent to the gnuplot subprocess.
Example:
p, err := gnuplot.NewPlotter("", false, false) if err != nil { /* handle error */ } defer p.Close()
func (*Plotter) CheckedCmd ¶
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 (*Plotter) Close ¶
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 (*Plotter) Cmd ¶
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 (*Plotter) PlotFunc ¶
PlotFunc will create a 2-d plot using `data` as x-coordinates and `fct(x[i])` as the y-coordinates. Example:
fct := funct (x float64) float64 { return math.Exp(float64(x) + 2.) } err = p.PlotFunc( []float64{0,1,2,3,4,5}, fct, "my title")
func (*Plotter) PlotNd ¶
PlotNd will create an n-dimensional plot (up to 3) with a title `title` and using the data from the var-arg `data`. example:
err = p.PlotNd( []float64{0,1,2,3}, // x-data []float64{0,1,2,3}, // y-data []float64{0,1,2,3}) // z-data
func (*Plotter) PlotX ¶
PlotX will create a 2-d plot using `data` as input and `title` as the plot title. The index of the element in the `data` slice will be used as the x-coordinate and its correspinding value as the y-coordinate.
func (*Plotter) PlotXY ¶
PlotXY will create a 2-d plot using `x` and `y` as input and `title` as the plot title. The values of the `x` slice will be used as x-coordinates and the matching values of `y` as y-coordinates (ie: for the same index). If the lengthes of the slices do not match, the range for the data will be the smallest size of the two slices.
func (*Plotter) PlotXYZ ¶
PlotXYZ will create a 3-d plot using `x`, `y` and `z` as input and `title` as the plot title. The data points to be plotted are the triplets (x[i], y[i], z[i]) where `i` runs from 0 to the smallest length of the 3 slices.
func (*Plotter) SetLabels ¶
SetLabels changes the labels for the x-,y- and z-axis in one go, depending on the size of the `labels` var-arg. Example:
err = p.SetLabels("x", "y", "z")
func (*Plotter) SetPlotCmd ¶
SetPlotCmd changes the command used for plotting by the gnuplot subprocess. Only valid plot commands are accepted (plot, splot)
func (*Plotter) SetStyle ¶
SetStyle changes the style used by the gnuplot subprocess. Only valid styles are accepted: