Table of contents Index

Module Gnuplot

submodule demo # demo.py -- Demonstrate the Gnuplot python module.
submodule oldplot # oldplot.py -- Obsolete functional interface to Gnuplot.
submodule test # test.py -- Exercise the Gnuplot.py module.
class AnyFile # Representation of any kind of file to be used by gnuplot.
class ArrayFile(AnyFile) # A file to which, upon creation, an array is written.
class Data(PlotItem) # Represents data from memory to be plotted with Gnuplot.
class DataException(Exception) # Raised for data in the wrong format
class File(PlotItem) # A PlotItem representing a file that contains gnuplot data.
class Func(PlotItem) # Represents a mathematical expression to plot.
class Gnuplot # Interface to a gnuplot program.
class GridData(PlotItem) # Holds data representing a function of two variables, for use in splot.
class GridFunc(GridData) # Holds data representing a function of two variables, for use in splot.
class OptionException(Exception) # Raised for unrecognized option(s)
class PlotItem # Plotitem represents an item that can be plotted by gnuplot.
class TempArrayFile(ArrayFile, TempFile) # An ArrayFile that is deleted automatically.
class TempFile(AnyFile) # A file that is automatically deleted.
class _unset # Used to represent unset keyword arguments.
def float_array(m) # Return the argument as a Numeric array of type at least 'Float32'.
def grid_function(f, xvals, yvals, typecode=None, ufunc=0) # Evaluate and tabulate a function on a grid.
def test_persist() # Determine whether gnuplot recognizes the option '-persist'.
def write_array(f, set, item_sep=' ', nest_prefix='', nest_suffix='\012', nest_sep='') # Write an array of arbitrary dimension to a file.
None CVS = None
list __all__ = ['oldplot']
string __cvs_version__ = '$Revision: 2.69 $'
string __file__ = '/home/mhagger/lib/python/Gnuplot/__init__.pyc'
list __path__ = ['/home/mhagger/lib/python/Gnuplot']
string __version__ = '1.3'
string _default_lpr = '| lpr'
string _default_term = 'x11'
string _gnuplot_command = 'gnuplot'
int _prefer_inline_data = 0
int _recognizes_binary_splot = 1
None _recognizes_persist = None

Description

This is the main module of the Gnuplot package.

Copyright (C) 1998,1999 Michael Haggerty

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details; it is available at <http://www.fsf.org/copyleft/gpl.html>, or by writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Written by Michael Haggerty <mhagger@blizzard.harvard.edu>. Inspired by and partly derived from an earlier version by Konrad Hinsen <hinsen@ibs.ibs.fr>. If you find a problem or have a suggestion, please let me know at <mhagger@blizzard.harvard.edu>. Other feedback would also be appreciated.

For information about how to use this module:

  1. Check the README file. 2. Look at the test code in demo.py and try running it by typing python demo.py or python __init__.py. 3a. For more details see the extensive documentation strings throughout this file. 3b. The docstrings have also been turned into html which can be read at <http://monsoon.harvard.edu/~mhagger/Gnuplot/Gnuplot-doc/>. However, the formatting is not perfect; when in doubt, double-check the docstrings.

You should import this file with import Gnuplot, not with 'from Gnuplot import *', because the module and the main class have the same name, `Gnuplot'.

To obtain the gnuplot plotting program itself, see <ftp://ftp.gnuplot.vt.edu/pub/gnuplot/faq/index.html>. Obviously you need to have gnuplot installed if you want to use Gnuplot.py.

The old command-based interface to gnuplot has been separated out into a separate module, oldplot.py. If you are still using that interface you should import Gnuplot.oldplot; otherwise you should stick to the more flexible object-oriented interface contained here.

Features:

Restrictions:

Bugs:

float_array(m)

Return the argument as a Numeric array of type at least 'Float32'.

Leave Float64 unchanged, but upcast all other types to Float32. Allow also for the possibility that the argument is a python native type that can be converted to a Numeric array using Numeric.asarray(), but in that case don't worry about downcasting to single-precision float.

grid_function(f, xvals, yvals, typecode=None, ufunc=0)

Evaluate and tabulate a function on a grid.

xvals and yvals should be 1-D arrays listing the values of x and y at which f should be tabulated. f should be a function taking two floating point arguments. The return value is a matrix M where M[i,j] = f(xvals[i],yvals[j]), which can for example be used in the GridData constructor.If ufunc=0, then f is evaluated at each pair of points using a Python loop. This can be slow if the number of points is large. If speed is an issue, you should write f in terms of Numeric ufuncs and use the ufunc=1 feature described next.If called with ufunc=1, then f should be a function that is composed entirely of ufuncs (i.e., a function that can operate element-by-element on whole matrices). It will be passed the xvals and yvals as rectangular matrices.

test_persist()

Determine whether gnuplot recognizes the option '-persist'.

If the configuration variable _recognizes_persist is set (i.e., to something other than 'None'), return that value. Otherwise, try to determine whether the installed version of gnuplot recognizes the -persist option. (If it doesn't, it should emit an error message with -persist in the first line.) Then set _recognizes_persist accordingly for future reference.

write_array(f, set, item_sep=' ', nest_prefix='', nest_suffix='\012', nest_sep='')

Write an array of arbitrary dimension to a file.

A general recursive array writer. The last four parameters allow a great deal of freedom in choosing the output format of the array. The defaults for those parameters give output that is gnuplot-readable. But using '(",", "{", "}", ", ")' would output an array in a format that Mathematica could read. item_sep should not contain % (or if it does, it should be escaped to '%%') since it is put into a format string.

The default 2-d file organization is, for example:

    set[0,0] set[0,1] ...
    set[1,0] set[1,1] ...

The 3-d format is, for example:

    set[0,0,0] set[0,0,1] ...
    set[0,1,0] set[0,1,1] ...    set[1,0,0] set[1,0,1] ...
    set[1,1,0] set[1,1,1] ...

Valid HTML 4.0! Made with CSS