~ubuntu-branches/ubuntu/trusty/python-gnuplot/trusty

« back to all changes in this revision

Viewing changes to build/lib/Gnuplot/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2005-01-23 00:42:37 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050123004237-0rfjkhe4ii7ky637
Tags: 1.7-5
Fix mouse control in generated plot windows (closes: #291294).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
# $Id: __init__.py,v 2.93 2001/01/26 19:00:27 mhagger Exp $
3
 
 
4
 
# Copyright (C) 1998-2001 Michael Haggerty <mhagger@alum.mit.edu>
5
 
#
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.
16
 
 
17
 
"""Gnuplot -- A pipe-based interface to the gnuplot plotting program.
18
 
 
19
 
This is the main module of the Gnuplot package.
20
 
 
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.
26
 
 
27
 
The Gnuplot.py home page is at
28
 
 
29
 
"Gnuplot.py", http://gnuplot-py.sourceforge.net
30
 
 
31
 
 
32
 
For information about how to use this module:
33
 
 
34
 
1. Check the README file.
35
 
 
36
 
2. Look at the example code in demo.py and try running it by typing
37
 
   'python demo.py' or 'python __init__.py'.
38
 
 
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.
42
 
 
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
46
 
   docstrings.
47
 
 
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
50
 
name, `Gnuplot'.
51
 
 
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.
55
 
 
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.
60
 
 
61
 
Features:
62
 
 
63
 
 o  Allows the creation of two or three dimensional plots from
64
 
    python.
65
 
 
66
 
 o  A gnuplot session is an instance of class 'Gnuplot'.  Multiple
67
 
    sessions can be open at once.  For example::
68
 
 
69
 
        g1 = Gnuplot.Gnuplot()
70
 
        g2 = Gnuplot.Gnuplot()
71
 
 
72
 
    Note that due to limitations on those platforms, opening multiple
73
 
    simultaneous sessions on Windows or Macintosh may not work
74
 
    correctly.  (Feedback?)
75
 
 
76
 
 o  The implicitly-generated gnuplot commands can be stored to a file
77
 
    instead of executed immediately::
78
 
 
79
 
        g = Gnuplot.Gnuplot('commands.txt')
80
 
 
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.
85
 
 
86
 
 o  Can pass arbitrary commands to the gnuplot command interpreter::
87
 
 
88
 
        g('set pointsize 2')
89
 
 
90
 
    (If this is all you want to do, you might consider using the
91
 
    lightweight GnuplotProcess class defined in gp.py.)
92
 
 
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:
96
 
 
97
 
    * 'Data(array1)' -- data from a Python list or NumPy array
98
 
                        (permits additional option 'cols' )
99
 
 
100
 
    * 'File('filename')' -- data from an existing data file (permits
101
 
                            additional option 'using' )
102
 
 
103
 
    * 'Func('exp(4.0 * sin(x))')' -- functions (passed as a string,
104
 
                                     evaluated by gnuplot)
105
 
 
106
 
    * 'GridData(m, x, y)' -- data tabulated on a grid of (x,y) values
107
 
                             (usually to be plotted in 3-D)
108
 
 
109
 
    See the documentation strings for those classes for more details.
110
 
 
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.
115
 
 
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
122
 
    prematurely.
123
 
 
124
 
 o  Can use 'replot' method to add datasets to an existing plot.
125
 
 
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
129
 
    this option.
130
 
 
131
 
 o  Can plot either directly to a postscript printer or to a
132
 
    postscript file via the 'hardcopy' method.
133
 
 
134
 
 o  Grid data for the splot command can be sent to gnuplot in binary
135
 
    format, saving time and disk space.
136
 
 
137
 
 o  Should work under Unix, Macintosh, and Windows.
138
 
 
139
 
Restrictions:
140
 
 
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.
144
 
 
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::
148
 
 
149
 
        g = Gnuplot.Gnuplot()
150
 
        g('set data style linespoints')
151
 
        g('set pointsize 5')
152
 
 
153
 
 -  There is no provision for missing data points in array data (which
154
 
    gnuplot allows via the 'set missing' command).
155
 
 
156
 
Bugs:
157
 
 
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.)
161
 
 
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.
166
 
 
167
 
"""
168
 
 
169
 
__version__ = '1.5'
170
 
__cvs_version__ = '$Revision: 2.93 $'
171
 
 
172
 
# Other modules that should be loaded for 'from Gnuplot import *':
173
 
__all__ = ['utils', 'funcutils', 'oldplot', ]
174
 
 
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
179
 
 
180
 
 
181
 
if __name__ == '__main__':
182
 
    import demo
183
 
    demo.demo()
184
 
 
185