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

Class Gnuplot

source code

Interface to a gnuplot program.

A Gnuplot represents a higher-level interface to a gnuplot
program.  It can plot 'PlotItem's, which represent each thing to
be plotted on the current graph.  It keeps a reference to each of
the 'PlotItems' used in the current plot, so that they (and their
associated temporary files) are not deleted prematurely.

Members:

    'itemlist' -- a list of the PlotItems that are associated with
        the current plot.  These are deleted whenever a new plot
        command is issued via the 'plot' method.

    'plotcmd' -- 'plot' or 'splot', depending on what was the last
        plot command.

Methods:

    '__init__' -- if a filename argument is specified, the
        commands will be written to that file instead of being
        piped to gnuplot.

    'plot' -- clear the old plot and old 'PlotItems', then plot
        the arguments in a fresh plot command.  Arguments can be:
        a 'PlotItem', which is plotted along with its internal
        options; a string, which is plotted as a 'Func'; or
        anything else, which is plotted as a 'Data'.

    'splot' -- like 'plot', except for 3-d plots.

    'hardcopy' -- replot the plot to a postscript file (if
        filename argument is specified) or pipe it to the printer
        as postscript othewise.  If the option 'color' is set to
        true, then output color postscript.

    'replot' -- replot the old items, adding any arguments as
        additional items as in the plot method.

    'refresh' -- issue (or reissue) the plot command using the
        current 'PlotItems'.

    '__call__' -- pass an arbitrary string to the gnuplot process,
        followed by a newline.

    'xlabel', 'ylabel', 'zlabel', 'title' -- set corresponding plot
        attribute.

    'interact' -- read lines from stdin and send them, one by one,
        to the gnuplot interpreter.  Basically you can type
        commands directly to the gnuplot command processor.

    'load' -- load a file (using the gnuplot 'load' command).

    'save' -- save gnuplot commands to a file (using gnuplot
        'save' command) If any of the 'PlotItem's is a temporary
        file, it will be deleted at the usual time and the save
        file will be pretty useless :-).

    'clear' -- clear the plot window (but not the itemlist).

    'reset' -- reset all gnuplot settings to their defaults and
        clear the current itemlist.

    'set_string' -- set or unset a gnuplot option whose value is a
        string.

    '_clear_queue' -- clear the current 'PlotItem' list.

    '_add_to_queue' -- add the specified items to the current
        'PlotItem' list.

Instance Methods [hide private]
 
__init__(self, filename=None, persist=None, debug=0)
Create a Gnuplot object.
source code
 
close(self) source code
 
__del__(self) source code
 
__call__(self, s)
Send a command string to gnuplot.
source code
 
refresh(self)
Refresh the plot, using the current 'PlotItem's.
source code
 
_clear_queue(self)
Clear the 'PlotItems' from the queue.
source code
 
_add_to_queue(self, items)
Add a list of items to the itemlist (but don't plot them).
source code
 
plot(self, *items, **keyw)
Draw a new plot.
source code
 
splot(self, *items, **keyw)
Draw a new three-dimensional plot.
source code
 
replot(self, *items, **keyw)
Replot the data, possibly adding new 'PlotItem's.
source code
 
interact(self)
Allow user to type arbitrary commands to gnuplot.
source code
 
clear(self)
Clear the plot window (without affecting the current itemlist).
source code
 
reset(self)
Reset all gnuplot settings to their defaults and clear itemlist.
source code
 
load(self, filename)
Load a file using gnuplot's 'load' command.
source code
 
save(self, filename)
Save the current plot commands using gnuplot's 'save' command.
source code
 
set_string(self, option, s=None)
Set a string option, or if s is omitted, unset the option.
source code
 
set_label(self, option, s=None, offset=None, font=None)
Set or clear a label option, which can include an offset or font.
source code
 
set_boolean(self, option, value)
Set an on/off option.
source code
 
set_range(self, option, value)
Set a range option (xrange, yrange, trange, urange, etc.).
source code
 
set(self, **keyw)
Set one or more settings at once from keyword arguments.
source code
 
xlabel(self, s=None, offset=None, font=None)
Set the plot's xlabel.
source code
 
ylabel(self, s=None, offset=None, font=None)
Set the plot's ylabel.
source code
 
zlabel(self, s=None, offset=None, font=None)
Set the plot's zlabel.
source code
 
title(self, s=None, offset=None, font=None)
Set the plot's title.
source code
 
hardcopy(self, filename=None, terminal='postscript', **keyw)
Create a hardcopy of the current plot.
source code
Class Variables [hide private]
  optiontypes = {'title': 'string', 'xlabel': 'string', 'ylabel'...
Method Details [hide private]

__init__(self, filename=None, persist=None, debug=0)
(Constructor)

source code 
Create a Gnuplot object.

Create a 'Gnuplot' object.  By default, this starts a gnuplot
process and prepares to write commands to it.

Keyword arguments:

  'filename=<string>' -- if a filename is specified, the
      commands are instead written to that file (e.g., for
      later use using 'load').

  'persist=1' -- start gnuplot with the '-persist' option
      (which creates a new plot window for each plot command).
      (This option is not available on older versions of
      gnuplot.)

  'debug=1' -- echo the gnuplot commands to stderr as well as
      sending them to gnuplot.

__call__(self, s)
(Call operator)

source code 

Send a command string to gnuplot.

Send the string s as a command to gnuplot, followed by a newline. All communication with the gnuplot process (except for inline data) is through this method.

refresh(self)

source code 

Refresh the plot, using the current 'PlotItem's.

Refresh the current plot by reissuing the gnuplot plot command corresponding to the current itemlist.

_add_to_queue(self, items)

source code 

Add a list of items to the itemlist (but don't plot them).

'items' is a sequence of items, each of which should be a 'PlotItem' of some kind, a string (interpreted as a function string for gnuplot to evaluate), or a numpy array (or something that can be converted to a numpy array).

plot(self, *items, **keyw)

source code 
Draw a new plot.

Clear the current plot and create a new 2-d plot containing
the specified items.  Each arguments should be of the
following types:

'PlotItem' (e.g., 'Data', 'File', 'Func') -- This is the most
    flexible way to call plot because the PlotItems can
    contain suboptions.  Moreover, PlotItems can be saved to
    variables so that their lifetime is longer than one plot
    command; thus they can be replotted with minimal overhead.

'string' (e.g., 'sin(x)') -- The string is interpreted as
    'Func(string)' (a function that is computed by gnuplot).

Anything else -- The object, which should be convertible to an
    array, is passed to the 'Data' constructor, and thus
    plotted as data.  If the conversion fails, an exception is
    raised.

splot(self, *items, **keyw)

source code 
Draw a new three-dimensional plot.

Clear the current plot and create a new 3-d plot containing
the specified items.  Arguments can be of the following types:

'PlotItem' (e.g., 'Data', 'File', 'Func', 'GridData' ) -- This
    is the most flexible way to call plot because the
    PlotItems can contain suboptions.  Moreover, PlotItems can
    be saved to variables so that their lifetime is longer
    than one plot command--thus they can be replotted with
    minimal overhead.

'string' (e.g., 'sin(x*y)') -- The string is interpreted as a
    'Func()' (a function that is computed by gnuplot).

Anything else -- The object is converted to a Data() item, and
    thus plotted as data.  Note that each data point should
    normally have at least three values associated with it
    (i.e., x, y, and z).  If the conversion fails, an
    exception is raised.

replot(self, *items, **keyw)

source code 

Replot the data, possibly adding new 'PlotItem's.

Replot the existing graph, using the items in the current itemlist. If arguments are specified, they are interpreted as additional items to be plotted alongside the existing items on the same graph. See 'plot' for details.

interact(self)

source code 

Allow user to type arbitrary commands to gnuplot.

Read stdin, line by line, and send each line as a command to gnuplot. End by typing C-d.

set_label(self, option, s=None, offset=None, font=None)

source code 

Set or clear a label option, which can include an offset or font.

If offset is specified, it should be a tuple of two integers or floats.

If font is specified, it is appended to the command as a string in double quotes. Its interpretation is terminal-dependent; for example, for postscript it might be 'Helvetica,14' for 14 point Helvetica.

set_boolean(self, option, value)

source code 

Set an on/off option. It is assumed that the way to turn the option on is to type `set <option>' and to turn it off, `set no<option>'.

set_range(self, option, value)

source code 

Set a range option (xrange, yrange, trange, urange, etc.). The value can be a string (which is passed as-is, without quotes) or a tuple (minrange,maxrange) of numbers or string expressions recognized by gnuplot. If either range is None then that range is passed as `*' (which means to autoscale).

set(self, **keyw)

source code 

Set one or more settings at once from keyword arguments. The allowed settings and their treatments are determined from the optiontypes mapping.

hardcopy(self, filename=None, terminal='postscript', **keyw)

source code 
Create a hardcopy of the current plot.

Output the current plot to the default printer (if configured)
or to the specified filename.

Note that gnuplot remembers the printer suboptions across
terminal changes (at least for postscript).  Therefore if you
set, for example, color=1 for one hardcopy then the next
hardcopy will also be color unless you explicitly choose
color=0.  Alternately you can force all of the options to
their defaults by setting mode='default'.  I consider this to
be a bug in gnuplot.

Keyword arguments:

  'filename=<string>' -- if a filename is specified, save the
      output in that file; otherwise print it immediately
      using the 'default_lpr' configuration option.

  'terminal=<string>' -- the type of gnuplot 'terminal' to use
      for the output (e.g., 'postscript', 'png', 'latex',
      etc).  Look in termdefs.py to see what terminal types
      are defined, or check termdefs.terminal_opts.keys().

The rest of the keyword arguments depend on the terminal type.

Keyword arguments for 'postscript' terminal:

  'mode=<string>' -- set the postscript submode ('landscape',
      'portrait', 'eps', or 'default').  The default is
      to leave this option unspecified.

  'eps=<bool>' -- shorthand for 'mode="eps"'; asks gnuplot to
      generate encapsulated postscript.

  'enhanced=<bool>' -- if set (the default), then generate
      enhanced postscript, which allows extra features like
      font-switching, superscripts, and subscripts in axis
      labels.  (Some old gnuplot versions do not support
      enhanced postscript; if this is the case set
      gp.GnuplotOpts.prefer_enhanced_postscript=None.)

  'color=<bool>' -- if set, create a plot with color.  Default
      is to leave this option unchanged.

  'solid=<bool>' -- if set, force lines to be solid (i.e., not
      dashed).

  'duplexing=<string>' -- set duplexing option ('defaultplex',
      'simplex', or 'duplex').  Only request double-sided
      printing if your printer can handle it.  Actually this
      option is probably meaningless since hardcopy() can only
      print a single plot at a time.

  'fontname=<string>' -- set the default font to <string>,
      which must be a valid postscript font.  The default is
      to leave this option unspecified.

  'fontsize=<double>' -- set the default font size, in
      postscript points.

Note that this command will return immediately even though it
might take gnuplot a while to actually finish working.  Be
sure to pause briefly before issuing another command that
might cause the temporary files to be deleted.


Class Variable Details [hide private]

optiontypes

Value:
{'title': 'string', 'xlabel': 'string', 'ylabel': 'string', 'zlabel': \
'string', 'xrange': 'range', 'yrange': 'range', 'zrange': 'range', 'tr\
ange': 'range', 'urange': 'range', 'vrange': 'range', 'parametric': 'b\
oolean', 'polar': 'boolean', 'output': 'string',}