Package PyFoam :: Package ThirdParty :: Package Gnuplot :: Module PlotItems
[hide private]
[frames] | no frames]

Module PlotItems

source code

PlotItems.py -- Objects that can be plotted by Gnuplot.

This module contains several types of PlotItems. PlotItems can be plotted by passing them to a Gnuplot.Gnuplot object. You can derive your own classes from the PlotItem hierarchy to customize their behavior.

Classes [hide private]
  _unset
Used to represent unset keyword arguments.
  PlotItem
Plotitem represents an item that can be plotted by gnuplot.
  Func
Represents a mathematical expression to plot.
  _FileItem
A PlotItem representing a file that contains gnuplot data.
  _NewFileItem
  _InlineFileItem
A _FileItem that actually indicates inline data.
  _FIFOWriter
Create a FIFO (named pipe), write to it, then delete it.
  _FIFOFileItem
A _FileItem based on a FIFO (named pipe).
Functions [hide private]
 
File(filename, **keyw)
Construct a _FileItem object referring to an existing file.
source code
 
Data(*data, **keyw)
Create and return a _FileItem representing the data from *data.
source code
 
GridData(data, xvals=None, yvals=None, inline=_unset, filename=None, **keyw)
Return a _FileItem representing a function of two variables.
source code
Function Details [hide private]

File(filename, **keyw)

source code 

Construct a _FileItem object referring to an existing file.

This is a convenience function that just returns a _FileItem that wraps the filename.

<filename> is a string holding the filename of an existing file. The keyword arguments are the same as those of the _FileItem constructor.

Data(*data, **keyw)

source code 
Create and return a _FileItem representing the data from *data.

Create a '_FileItem' object (which is a type of 'PlotItem') out of
one or more Float Python numpy arrays (or objects that can be
converted to a float numpy array).  If the routine is passed a
single with multiple dimensions, then the last index ranges over
the values comprising a single data point (e.g., [<x>, <y>,
<sigma>]) and the rest of the indices select the data point.  If
passed a single array with 1 dimension, then each point is
considered to have only one value (i.e., by default the values
will be plotted against their indices).  If the routine is passed
more than one array, they must have identical shapes, and then
each data point is composed of one point from each array.  E.g.,
'Data(x,x**2)' is a 'PlotItem' that represents x squared as a
function of x.  For the output format, see the comments for
'write_array()'.

How the data are written to gnuplot depends on the 'inline'
argument and preference settings for the platform in use.

Keyword arguments:

    'cols=<tuple>' -- write only the specified columns from each
        data point to the file.  Since cols is used by python, the
        columns should be numbered in the python style (starting
        from 0), not the gnuplot style (starting from 1).

    'inline=<bool>' -- transmit the data to gnuplot 'inline'
        rather than through a temporary file.  The default is the
        value of gp.GnuplotOpts.prefer_inline_data.

    'filename=<string>' -- save data to a permanent file.

The keyword arguments recognized by '_FileItem' can also be used
here.

GridData(data, xvals=None, yvals=None, inline=_unset, filename=None, **keyw)

source code 
Return a _FileItem representing a function of two variables.

'GridData' represents a function that has been tabulated on a
rectangular grid.  The data are written to a file; no copy is kept
in memory.

Arguments:

    'data' -- the data to plot: a 2-d array with dimensions
        (numx,numy).

    'xvals' -- a 1-d array with dimension 'numx'

    'yvals' -- a 1-d array with dimension 'numy'

    'binary=<bool>' -- send data to gnuplot in binary format?

    'inline=<bool>' -- send data to gnuplot "inline"?

    'filename=<string>' -- save data to a permanent file.

Note the unusual argument order!  The data are specified *before*
the x and y values.  (This inconsistency was probably a mistake;
after all, the default xvals and yvals are not very useful.)

'data' must be a data array holding the values of a function
f(x,y) tabulated on a grid of points, such that 'data[i,j] ==
f(xvals[i], yvals[j])'.  If 'xvals' and/or 'yvals' are omitted,
integers (starting with 0) are used for that coordinate.  The data
are written to a temporary file; no copy of the data is kept in
memory.

If 'binary=0' then the data are written to a datafile as 'x y
f(x,y)' triplets (y changes most rapidly) that can be used by
gnuplot's 'splot' command.  Blank lines are included each time the
value of x changes so that gnuplot knows to plot a surface through
the data.

If 'binary=1' then the data are written to a file in a binary
format that 'splot' can understand.  Binary format is faster and
usually saves disk space but is not human-readable.  If your
version of gnuplot doesn't support binary format (it is a
recently-added feature), this behavior can be disabled by setting
the configuration variable
'gp.GnuplotOpts.recognizes_binary_splot=0' in the appropriate
gp*.py file.

Thus if you have three arrays in the above format and a Gnuplot
instance called g, you can plot your data by typing
'g.splot(Gnuplot.GridData(data,xvals,yvals))'.