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

Class PlotItem

source code

Plotitem represents an item that can be plotted by gnuplot.

For the finest control over the output, you can create 'PlotItems'
yourself with additional keyword options, or derive new classes
from 'PlotItem'.

The handling of options is complicated by the attempt to allow
options and their setting mechanism to be inherited conveniently.
Note first that there are some options that can only be set in the
constructor then never modified, and others that can be set in the
constructor and/or modified using the 'set_option()' member
function.  The former are always processed within '__init__'.  The
latter are always processed within 'set_option', which is called
by the constructor.

'set_option' is driven by a class-wide dictionary called
'_option_list', which is a mapping '{ <option> : <setter> }' from
option name to the function object used to set or change the
option.  <setter> is a function object that takes two parameters:
'self' (the 'PlotItem' instance) and the new value requested for
the option.  If <setter> is 'None', then the option is not allowed
to be changed after construction and an exception is raised.

Any 'PlotItem' that needs to add options can add to this
dictionary within its class definition.  Follow one of the
examples in this file.  Alternatively it could override the
'set_option' member function if it needs to do wilder things.

Members:

  '_basecommand' -- a string holding the elementary argument that
      must be passed to gnuplot's `plot' command for this item;
      e.g., 'sin(x)' or '"filename.dat"'.

  '_options' -- a dictionary of (<option>,<string>) tuples
      corresponding to the plot options that have been set for
      this instance of the PlotItem.  <option> is the option as
      specified by the user; <string> is the string that needs to
      be set in the command line to set that option (or None if no
      string is needed).  Example::

          {'title' : ('Data', 'title "Data"'),
           'with' : ('linespoints', 'with linespoints')}

Instance Methods [hide private]
 
__init__(self, **keyw)
Construct a 'PlotItem'.
source code
 
get_option(self, name)
Return the setting of an option.
source code
 
set_option(self, **keyw)
Set or change a plot option for this PlotItem.
source code
 
set_string_option(self, option, value, default, fmt)
Set an option that takes a string value.
source code
 
clear_option(self, name)
Clear (unset) a plot option.
source code
 
get_base_command_string(self) source code
 
get_command_option_string(self) source code
 
command(self)
Build the plot command to be sent to gnuplot.
source code
 
pipein(self, f)
Pipe necessary inline data to gnuplot.
source code
Class Variables [hide private]
  _option_list = {'axes': lambda self, axes: self.set_string_opt...
  _option_sequence = ['binary', 'index', 'every', 'thru', 'using...
Method Details [hide private]

__init__(self, **keyw)
(Constructor)

source code 
Construct a 'PlotItem'.

Keyword options:

  'with_=<string>' -- choose how item will be plotted, e.g.,
      with_='points 3 3'.

  'title=<string>' -- set the title to be associated with the item
      in the plot legend.

  'title=None' -- choose 'notitle' option (omit item from legend).

Note that omitting the title option is different than setting
'title=None'; the former chooses gnuplot's default whereas the
latter chooses 'notitle'.

get_option(self, name)

source code 

Return the setting of an option. May be overridden.

set_option(self, **keyw)

source code 

Set or change a plot option for this PlotItem.

See documentation for '__init__' for information about allowed options. This function can be overridden by derived classes to allow additional options, in which case those options will also be allowed by '__init__' for the derived class. However, it is easier to define a new '_option_list' variable for the derived class.

clear_option(self, name)

source code 

Clear (unset) a plot option. No error if option was not set.

command(self)

source code 

Build the plot command to be sent to gnuplot.

Build and return the plot command, with options, necessary to display this item. If anything else needs to be done once per plot, it can be done here too.

pipein(self, f)

source code 

Pipe necessary inline data to gnuplot.

If the plot command requires data to be put on stdin (i.e., 'plot "-"'), this method should put that data there. Can be overridden in derived classes.


Class Variable Details [hide private]

_option_list

Value:
{'axes': lambda self, axes: self.set_string_option('axes', axes, None,\
 'axes %s'), 'with': lambda self, with_: self.set_string_option('with'\
, with_, None, 'with %s'), 'title': lambda self, title: self.set_strin\
g_option('title', title, 'notitle', 'title "%s"'),}

_option_sequence

Value:
['binary', 'index', 'every', 'thru', 'using', 'smooth', 'axes', 'title\
', 'with']