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 , 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.
Methods
|
|
|
|
__call__
|
__call__ ( self, s )
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.
|
|
__init__
|
__init__ (
self,
filename=None,
persist=None,
debug=0,
)
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.
Exceptions
|
|
Errors.OptionError( 'Gnuplot with output to file does not allow ' 'persist option.' )
|
|
|
_add_to_queue
|
_add_to_queue ( self, items )
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 Numeric array (or
something that can be converted to a Numeric array).
|
|
_clear_queue
|
_clear_queue ( self )
Clear the PlotItems from the queue.
|
|
clear
|
clear ( self )
Clear the plot window (without affecting the current itemlist).
|
|
hardcopy
|
hardcopy (
self,
filename=None,
terminal='postscript',
**keyw,
)
Create a hardcopy of the current plot.
Create a postscript hardcopy of the current plot to the
default printer (if configured) or to the specified filename.
Note that gnuplot remembers the postscript suboptions across
terminal changes. 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). At the moment only postscript is implemented.
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.
Exceptions
|
|
Errors.OptionError( 'default_lpr is not set, so you can only print to a file.' )
Errors.OptionError('Terminal "%s" is not configured in Gnuplot.py.' %( terminal, ) )
Errors.OptionError('The following options are unrecognized: %s' %( string.join( keyw.keys(), ', ' ), ) )
|
|
|
interact
|
interact ( self )
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.
|
|
load
|
load ( self, filename )
Load a file using gnuplot's load command.
|
|
plot
|
plot (
self,
*items,
*keyw,
)
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.
|
|
refresh
|
refresh ( self )
Refresh the plot, using the current 'PlotItem's.
Refresh the current plot by reissuing the gnuplot plot command
corresponding to the current itemlist.
|
|
replot
|
replot (
self,
*items,
*keyw,
)
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.
|
|
reset
|
reset ( self )
Reset all gnuplot settings to their defaults and clear itemlist.
|
|
save
|
save ( self, filename )
Save the current plot commands using gnuplot's save command.
|
|
set
|
set ( self, **keyw )
Set one or more settings at once from keyword arguments.
The allowed settings and their treatments are determined from
the optiontypes mapping.
|
|
set_boolean
|
set_boolean (
self,
option,
value,
)
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
|
set_range (
self,
option,
value,
)
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_string
|
set_string (
self,
option,
s=None,
)
Set a string option, or if s is omitted, unset the option.
|
|
splot
|
splot (
self,
*items,
*keyw,
)
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.
|
|
title
|
title ( self, s=None )
Set the plot's title.
|
|
xlabel
|
xlabel ( self, s=None )
Set the plot's xlabel.
|
|
ylabel
|
ylabel ( self, s=None )
Set the plot's ylabel.
|
|