2
# $Id: __init__.py,v 2.93 2001/01/26 19:00:27 mhagger Exp $
4
# Copyright (C) 1998-2001 Michael Haggerty <mhagger@alum.mit.edu>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version. This program is distributed in
10
# the hope that it will be useful, but WITHOUT ANY WARRANTY; without
11
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
# PARTICULAR PURPOSE. See the GNU General Public License for more
13
# details; it is available at <http://www.fsf.org/copyleft/gpl.html>,
14
# or by writing to the Free Software Foundation, Inc., 59 Temple Place
15
# - Suite 330, Boston, MA 02111-1307, USA.
17
"""Gnuplot -- A pipe-based interface to the gnuplot plotting program.
19
This is the main module of the Gnuplot package.
21
Written by "Michael Haggerty", mailto:mhagger@alum.mit.edu. Inspired
22
by and partly derived from an earlier version by "Konrad Hinsen",
23
mailto:hinsen@ibs.ibs.fr. If you find a problem or have a suggestion,
24
please "let me know", mailto:mhagger@alum.mit.edu. Other feedback
25
would also be appreciated.
27
The Gnuplot.py home page is at
29
"Gnuplot.py", http://gnuplot-py.sourceforge.net
32
For information about how to use this module:
34
1. Check the README file.
36
2. Look at the example code in demo.py and try running it by typing
37
'python demo.py' or 'python __init__.py'.
39
3. For more details see the extensive documentation strings
40
throughout the python source files, especially this file,
41
_Gnuplot.py, PlotItems.py, and gp_unix.py.
43
4. The docstrings have also been turned into html which can be read
44
"here", http://gnuplot-py.sourceforge.net/doc. However, the
45
formatting is not perfect; when in doubt, double-check the
48
You should import this file with 'import Gnuplot', not with 'from
49
Gnuplot import *', because the module and the main class have the same
52
To obtain the gnuplot plotting program itself, see "the gnuplot FAQ",
53
ftp://ftp.gnuplot.vt.edu/pub/gnuplot/faq/index.html. Obviously you
54
need to have gnuplot installed if you want to use Gnuplot.py.
56
The old command-based interface to gnuplot has been separated out into
57
a separate module, oldplot.py. If you are still using that interface
58
you should 'import Gnuplot.oldplot'; otherwise you should stick to the
59
more flexible object-oriented interface contained here.
63
o Allows the creation of two or three dimensional plots from
66
o A gnuplot session is an instance of class 'Gnuplot'. Multiple
67
sessions can be open at once. For example::
69
g1 = Gnuplot.Gnuplot()
70
g2 = Gnuplot.Gnuplot()
72
Note that due to limitations on those platforms, opening multiple
73
simultaneous sessions on Windows or Macintosh may not work
74
correctly. (Feedback?)
76
o The implicitly-generated gnuplot commands can be stored to a file
77
instead of executed immediately::
79
g = Gnuplot.Gnuplot('commands.txt')
81
The 'commands.txt' file can then be run later with gnuplot's
82
'load' command. Beware, however: the plot commands may depend on
83
the existence of temporary files, which will probably be deleted
84
before you use the command file.
86
o Can pass arbitrary commands to the gnuplot command interpreter::
90
(If this is all you want to do, you might consider using the
91
lightweight GnuplotProcess class defined in gp.py.)
93
o A Gnuplot object knows how to plot objects of type 'PlotItem'.
94
Any PlotItem can have optional 'title' and/or 'with' suboptions.
95
Builtin PlotItem types:
97
* 'Data(array1)' -- data from a Python list or NumPy array
98
(permits additional option 'cols' )
100
* 'File('filename')' -- data from an existing data file (permits
101
additional option 'using' )
103
* 'Func('exp(4.0 * sin(x))')' -- functions (passed as a string,
104
evaluated by gnuplot)
106
* 'GridData(m, x, y)' -- data tabulated on a grid of (x,y) values
107
(usually to be plotted in 3-D)
109
See the documentation strings for those classes for more details.
111
o PlotItems are implemented as objects that can be assigned to
112
variables and plotted repeatedly. Most of their plot options can
113
also be changed with the new 'set_option()' member functions then
114
they can be replotted with their new options.
116
o Communication of commands to gnuplot is via a one-way pipe.
117
Communication of data from python to gnuplot is via inline data
118
(through the command pipe) or via temporary files. Temp files are
119
deleted automatically when their associated 'PlotItem' is deleted.
120
The PlotItems in use by a Gnuplot object at any given time are
121
stored in an internal list so that they won't be deleted
124
o Can use 'replot' method to add datasets to an existing plot.
126
o Can make persistent gnuplot windows by using the constructor option
127
'persist=1'. Such windows stay around even after the gnuplot
128
program is exited. Note that only newer version of gnuplot support
131
o Can plot either directly to a postscript printer or to a
132
postscript file via the 'hardcopy' method.
134
o Grid data for the splot command can be sent to gnuplot in binary
135
format, saving time and disk space.
137
o Should work under Unix, Macintosh, and Windows.
141
- Relies on the Numeric Python extension. This can be obtained from
142
"SourceForge", http://sourceforge.net/projects/numpy/. If you're
143
interested in gnuplot, you would probably also want NumPy anyway.
145
- Only a small fraction of gnuplot functionality is implemented as
146
explicit method functions. However, you can give arbitrary
147
commands to gnuplot manually::
149
g = Gnuplot.Gnuplot()
150
g('set data style linespoints')
153
- There is no provision for missing data points in array data (which
154
gnuplot allows via the 'set missing' command).
158
- No attempt is made to check for errors reported by gnuplot. On
159
unix any gnuplot error messages simply appear on stderr. (I don't
160
know what happens under Windows.)
162
- All of these classes perform their resource deallocation when
163
'__del__' is called. Normally this works fine, but there are
164
well-known cases when Python's automatic resource deallocation
165
fails, which can leave temporary files around.
170
__cvs_version__ = '$Revision: 2.93 $'
172
# Other modules that should be loaded for 'from Gnuplot import *':
173
__all__ = ['utils', 'funcutils', 'oldplot', ]
175
from gp import GnuplotOpts, GnuplotProcess, test_persist
176
from PlotItems import OptionException, DataException, \
177
PlotItem, Func, File, Data, GridData
178
from _Gnuplot import Gnuplot
181
if __name__ == '__main__':