gnuplot

package
v0.0.0-...-cf52c2c Latest Latest
Warning

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

Go to latest
Published: May 12, 2014 License: BSD-2-Clause Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

type Func func(x float64) float64

Func is a 1-d function which can be plotted with gnuplot

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

func NewPlotter(fname string, persist, debug bool) (*Plotter, error)

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

func (self *Plotter) 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 (*Plotter) Close

func (self *Plotter) 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 (*Plotter) Cmd

func (self *Plotter) 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 (*Plotter) PlotFunc

func (self *Plotter) PlotFunc(data []float64, fct Func, title string, nr int) error

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

func (self *Plotter) PlotNd(extra string, data ...[]float64) error

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

func (self *Plotter) PlotX(data []float64, extra string) error

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

func (self *Plotter) PlotXY(x, y []float64, extra string) error

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

func (self *Plotter) PlotXYZ(x, y, z []float64, extra string) error

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) ResetPlot

func (self *Plotter) ResetPlot() (err error)

ResetPlot clears up all plots and sets the Plotter state anew.

func (*Plotter) SetLabels

func (self *Plotter) SetLabels(labels ...string) error

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

func (self *Plotter) SetPlotCmd(cmd string) (err error)

SetPlotCmd changes the command used for plotting by the gnuplot subprocess. Only valid plot commands are accepted (plot, splot)

func (*Plotter) SetStyle

func (self *Plotter) SetStyle(style string)

SetStyle changes the style used by the gnuplot subprocess. Only valid styles are accepted:

func (*Plotter) SetXLabel

func (self *Plotter) SetXLabel(label string) error

SetXLabel changes the label for the x-axis

func (*Plotter) SetYLabel

func (self *Plotter) SetYLabel(label string) error

SetYLabel changes the label for the y-axis

func (*Plotter) SetZLabel

func (self *Plotter) SetZLabel(label string) error

SetZLabel changes the label for the z-axis

Jump to

Keyboard shortcuts

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