1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
"http://www.w3.org/TR/html40/loose.dtd">
7
<title>Class: Gnuplot</title>
10
<body bgcolor="#ffffff">
12
<p><i><a href="../../index.html">Table of Contents</a></i></p>
14
<table border="0" cellpadding="5" cellspacing="0" width="100%">
20
bgcolor="#88bbee"><font color="#000000">Class: Gnuplot</font>
24
align="right"><font color="#000000">Gnuplot/_Gnuplot.py</font>
30
<h3>Interface to a gnuplot program.</h3>
31
<p> A Gnuplot represents a higher-level interface to a gnuplot
32
program. It can plot 'PlotItem's, which represent each thing to
33
be plotted on the current graph. It keeps a reference to each of
34
the <code>PlotItems</code> used in the current plot, so that they (and their
35
associated temporary files) are not deleted prematurely.</p>
38
<dt> <code>itemlist</code></dt>
39
<dd>a list of the PlotItems that are associated with
40
the current plot. These are deleted whenever a new plot
41
command is issued via the <code>plot</code> method.</dd>
42
<dt> <code>plotcmd</code></dt>
43
<dd><code>plot</code> or <code>splot</code>, depending on what was the last
48
<dt> <code>__init__</code></dt>
49
<dd>if a filename argument is specified, the
50
commands will be written to that file instead of being
51
piped to gnuplot.</dd>
52
<dt> <code>plot</code></dt>
53
<dd>clear the old plot and old <code>PlotItems</code>, then plot
54
the arguments in a fresh plot command. Arguments can be:
55
a <code>PlotItem</code>, which is plotted along with its internal
56
options; a string, which is plotted as a 'Func'; or
57
anything else, which is plotted as a <code>Data</code>.</dd>
58
<dt> <code>splot</code></dt>
59
<dd>like <code>plot</code>, except for 3-d plots.</dd>
60
<dt> <code>hardcopy</code></dt>
61
<dd>replot the plot to a postscript file (if
62
filename argument is specified) or pipe it to the printer
63
as postscript othewise. If the option <code>color</code> is set to
64
true, then output color postscript.</dd>
65
<dt> <code>replot</code></dt>
66
<dd>replot the old items, adding any arguments as
67
additional items as in the plot method.</dd>
68
<dt> <code>refresh</code></dt>
69
<dd>issue (or reissue) the plot command using the
70
current <code>PlotItems</code>.</dd>
71
<dt> <code>__call__</code></dt>
72
<dd>pass an arbitrary string to the gnuplot process,
73
followed by a newline.</dd>
74
<dt> <code>xlabel</code>, <code>ylabel</code>, <code>title</code></dt>
75
<dd>set corresponding plot
77
<dt> <code>interact</code></dt>
78
<dd>read lines from stdin and send them, one by one,
79
to the gnuplot interpreter. Basically you can type
80
commands directly to the gnuplot command processor.</dd>
81
<dt> <code>load</code></dt>
82
<dd>load a file (using the gnuplot <code>load</code> command).</dd>
83
<dt> <code>save</code></dt>
84
<dd>save gnuplot commands to a file (using gnuplot
85
<code>save</code> command) If any of the 'PlotItem's is a temporary
86
file, it will be deleted at the usual time and the save
87
file will be pretty useless :-).</dd>
88
<dt> <code>clear</code></dt>
89
<dd>clear the plot window (but not the itemlist).</dd>
90
<dt> <code>reset</code></dt>
91
<dd>reset all gnuplot settings to their defaults and
92
clear the current itemlist.</dd>
93
<dt> <code>set_string</code></dt>
94
<dd>set or unset a gnuplot option whose value is a
96
<dt> <code>_clear_queue</code></dt>
97
<dd>clear the current <code>PlotItem</code> list.</dd>
98
<dt> <code>_add_to_queue</code></dt>
99
<dd>add the specified items to the current
100
<code>PlotItem</code> list.</dd>
102
<table border="0" cellpadding="5" cellspacing="0" width="100%">
105
<th bgcolor="#99ccff"
111
<font color="#000000">
112
<a name="Methods">Methods</a>
115
<th bgcolor="#99ccff"
120
<font color="#000000"> </font>
127
<table border="0" cellspacing="2" cellpadding="2" width="100%">
129
<td align="LEFT" valign="TOP">
130
<a href="#__call__">__call__</a><br>
131
<a href="#__init__">__init__</a><br>
132
<a href="#_add_to_queue">_add_to_queue</a><br>
133
<a href="#_clear_queue">_clear_queue</a><br>
134
<a href="#clear">clear</a><br>
135
<a href="#hardcopy">hardcopy</a><br>
136
<a href="#interact">interact</a><br>
137
<a href="#load">load</a><br>
139
<td align="LEFT" valign="TOP">
140
<a href="#plot">plot</a><br>
141
<a href="#refresh">refresh</a><br>
142
<a href="#replot">replot</a><br>
143
<a href="#reset">reset</a><br>
144
<a href="#save">save</a><br>
145
<a href="#set">set</a><br>
146
<a href="#set_boolean">set_boolean</a><br>
147
<a href="#set_label">set_label</a><br>
149
<td align="LEFT" valign="TOP">
150
<a href="#set_range">set_range</a><br>
151
<a href="#set_string">set_string</a><br>
152
<a href="#splot">splot</a><br>
153
<a href="#title">title</a><br>
154
<a href="#xlabel">xlabel</a><br>
155
<a href="#ylabel">ylabel</a><br>
162
<th bgcolor="#99ccff"
168
<font color="#000000">
169
<a name="__call__"></a>
172
<th bgcolor="#99ccff"
177
<font color="#000000">__call__ </font>
182
<font color="#000088"><pre>
187
<h3>Send a command string to gnuplot.</h3>
188
<p> Send the string s as a command to gnuplot, followed by a
189
newline. All communication with the gnuplot process (except
190
for inline data) is through this method.</p>
193
<th bgcolor="#99ccff"
199
<font color="#000000">
200
<a name="__init__"></a>
203
<th bgcolor="#99ccff"
208
<font color="#000000">__init__ </font>
213
<font color="#000088"><pre>
223
<h3>Create a Gnuplot object.</h3>
224
<p> Create a <code>Gnuplot</code> object. By default, this starts a gnuplot
225
process and prepares to write commands to it.</p>
226
<h4> Keyword arguments:</h4>
228
<dt> <code>filename=<string></code></dt>
229
<dd>if a filename is specified, the
230
commands are instead written to that file (e.g., for
231
later use using <code>load</code>).</dd>
232
<dt> <code>persist=1</code></dt>
233
<dd>start gnuplot with the <code>-persist</code> option
234
(which creates a new plot window for each plot command).
235
(This option is not available on older versions of
237
<dt> <code>debug=1</code></dt>
238
<dd>echo the gnuplot commands to stderr as well as
239
sending them to gnuplot.</dd>
241
<table border="0" cellpadding="5" cellspacing="0" width="100%">
244
<th bgcolor="#99ccff"
250
<font color="#000000">
251
<a name="Exceptions">Exceptions</a>
254
<th bgcolor="#99ccff"
259
<font color="#000000"> </font>
265
Errors.OptionError( 'Gnuplot with output to file does not allow ' 'persist option.' )<br>
271
<th bgcolor="#99ccff"
277
<font color="#000000">
278
<a name="_add_to_queue"></a>
281
<th bgcolor="#99ccff"
286
<font color="#000000">_add_to_queue </font>
291
<font color="#000088"><pre>
292
_add_to_queue ( self, items )
296
<h3>Add a list of items to the itemlist (but don't plot them).</h3>
297
<p> <code>items</code> is a sequence of items, each of which should be a
298
<code>PlotItem</code> of some kind, a string (interpreted as a function
299
string for gnuplot to evaluate), or a Numeric array (or
300
something that can be converted to a Numeric array).</p>
303
<th bgcolor="#99ccff"
309
<font color="#000000">
310
<a name="_clear_queue"></a>
313
<th bgcolor="#99ccff"
318
<font color="#000000">_clear_queue </font>
323
<font color="#000088"><pre>
324
_clear_queue ( self )
328
<p>Clear the <code>PlotItems</code> from the queue.</p>
331
<th bgcolor="#99ccff"
337
<font color="#000000">
338
<a name="clear"></a>
341
<th bgcolor="#99ccff"
346
<font color="#000000">clear </font>
351
<font color="#000088"><pre>
356
<p>Clear the plot window (without affecting the current itemlist).</p>
359
<th bgcolor="#99ccff"
365
<font color="#000000">
366
<a name="hardcopy"></a>
369
<th bgcolor="#99ccff"
374
<font color="#000000">hardcopy </font>
379
<font color="#000088"><pre>
383
terminal='postscript',
389
<h3>Create a hardcopy of the current plot.</h3>
390
<p> Create a postscript hardcopy of the current plot to the
391
default printer (if configured) or to the specified filename.</p>
392
<p> Note that gnuplot remembers the postscript suboptions across
393
terminal changes. Therefore if you set, for example, color=1
394
for one hardcopy then the next hardcopy will also be color
395
unless you explicitly choose color=0. Alternately you can
396
force all of the options to their defaults by setting
397
mode=<code>default</code>. I consider this to be a bug in gnuplot.</p>
398
<h4> Keyword arguments:</h4>
400
<dt> <code>filename=<string></code></dt>
401
<dd>if a filename is specified, save the
402
output in that file; otherwise print it immediately
403
using the <code>default_lpr</code> configuration option.</dd>
404
<dt> <code>terminal=<string></code></dt>
405
<dd>the type of gnuplot <code>terminal</code> to use
406
for the output (e.g., <code>postscript</code>, <code>png</code>, <code>latex</code>,
407
etc). At the moment only <code>postscript</code> is implemented.</dd>
409
<p> The rest of the keyword arguments depend on the terminal type.</p>
410
<h4> Keyword arguments for <code>postscript</code> terminal:</h4>
412
<dt> <code>mode=<string></code></dt>
413
<dd>set the postscript submode (<code>landscape</code>,
414
<code>portrait</code>, <code>eps</code>, or <code>default</code>). The default is
415
to leave this option unspecified.</dd>
416
<dt> <code>eps=<bool></code></dt>
417
<dd>shorthand for 'mode="eps"'; asks gnuplot to
418
generate encapsulated postscript.</dd>
419
<dt> <code>enhanced=<bool></code></dt>
420
<dd>if set (the default), then generate
421
enhanced postscript, which allows extra features like
422
font-switching, superscripts, and subscripts in axis
423
labels. (Some old gnuplot versions do not support
424
enhanced postscript; if this is the case set
425
gp.GnuplotOpts.prefer_enhanced_postscript=None.)</dd>
426
<dt> <code>color=<bool></code></dt>
427
<dd>if set, create a plot with color. Default
428
is to leave this option unchanged.</dd>
429
<dt> <code>solid=<bool></code></dt>
430
<dd>if set, force lines to be solid (i.e., not
432
<dt> <code>duplexing=<string></code></dt>
433
<dd>set duplexing option (<code>defaultplex</code>,
434
<code>simplex</code>, or <code>duplex</code>). Only request double-sided
435
printing if your printer can handle it. Actually this
436
option is probably meaningless since hardcopy() can only
437
print a single plot at a time.</dd>
438
<dt> <code>fontname=<string></code></dt>
439
<dd>set the default font to <string>,
440
which must be a valid postscript font. The default is
441
to leave this option unspecified.</dd>
442
<dt> <code>fontsize=<double></code></dt>
443
<dd>set the default font size, in
444
postscript points.</dd>
446
<p> Note that this command will return immediately even though it
447
might take gnuplot a while to actually finish working. Be
448
sure to pause briefly before issuing another command that
449
might cause the temporary files to be deleted.</p>
450
<table border="0" cellpadding="5" cellspacing="0" width="100%">
453
<th bgcolor="#99ccff"
459
<font color="#000000">
460
<a name="Exceptions">Exceptions</a>
463
<th bgcolor="#99ccff"
468
<font color="#000000"> </font>
474
Errors.OptionError( 'default_lpr is not set, so you can only print to a file.' )<br>
475
Errors.OptionError('Terminal "%s" is not configured in Gnuplot.py.' %( terminal, ) )<br>
476
Errors.OptionError('The following options are unrecognized: %s' %( string.join( keyw.keys(), ', ' ), ) )<br>
482
<th bgcolor="#99ccff"
488
<font color="#000000">
489
<a name="interact"></a>
492
<th bgcolor="#99ccff"
497
<font color="#000000">interact </font>
502
<font color="#000088"><pre>
507
<h3>Allow user to type arbitrary commands to gnuplot.</h3>
508
<p> Read stdin, line by line, and send each line as a command to
509
gnuplot. End by typing C-d.</p>
512
<th bgcolor="#99ccff"
518
<font color="#000000">
519
<a name="load"></a>
522
<th bgcolor="#99ccff"
527
<font color="#000000">load </font>
532
<font color="#000088"><pre>
533
load ( self, filename )
537
<p>Load a file using gnuplot's <code>load</code> command.</p>
540
<th bgcolor="#99ccff"
546
<font color="#000000">
547
<a name="plot"></a>
550
<th bgcolor="#99ccff"
555
<font color="#000000">plot </font>
560
<font color="#000088"><pre>
569
<h3>Draw a new plot.</h3>
570
<p> Clear the current plot and create a new 2-d plot containing
571
the specified items. Each arguments should be of the
574
<dt> <code>PlotItem</code> (e.g., <code>Data</code>, <code>File</code>, <code>Func</code>)</dt>
576
flexible way to call plot because the PlotItems can
577
contain suboptions. Moreover, PlotItems can be saved to
578
variables so that their lifetime is longer than one plot
579
command; thus they can be replotted with minimal overhead.</dd>
580
<dt> <code>string</code> (e.g., <code>sin(x)</code>)</dt>
581
<dd>The string is interpreted as
582
<code>Func(string)</code> (a function that is computed by gnuplot).</dd>
583
<dt> Anything else</dt>
584
<dd>The object, which should be convertible to an
585
array, is passed to the <code>Data</code> constructor, and thus
586
plotted as data. If the conversion fails, an exception is
591
<th bgcolor="#99ccff"
597
<font color="#000000">
598
<a name="refresh"></a>
601
<th bgcolor="#99ccff"
606
<font color="#000000">refresh </font>
611
<font color="#000088"><pre>
616
<h3>Refresh the plot, using the current 'PlotItem's.</h3>
617
<p> Refresh the current plot by reissuing the gnuplot plot command
618
corresponding to the current itemlist.</p>
621
<th bgcolor="#99ccff"
627
<font color="#000000">
628
<a name="replot"></a>
631
<th bgcolor="#99ccff"
636
<font color="#000000">replot </font>
641
<font color="#000088"><pre>
650
<h3>Replot the data, possibly adding new 'PlotItem's.</h3>
651
<p> Replot the existing graph, using the items in the current
652
itemlist. If arguments are specified, they are interpreted as
653
additional items to be plotted alongside the existing items on
654
the same graph. See <code>plot</code> for details.</p>
657
<th bgcolor="#99ccff"
663
<font color="#000000">
664
<a name="reset"></a>
667
<th bgcolor="#99ccff"
672
<font color="#000000">reset </font>
677
<font color="#000088"><pre>
682
<p>Reset all gnuplot settings to their defaults and clear itemlist.</p>
685
<th bgcolor="#99ccff"
691
<font color="#000000">
692
<a name="save"></a>
695
<th bgcolor="#99ccff"
700
<font color="#000000">save </font>
705
<font color="#000088"><pre>
706
save ( self, filename )
710
<p>Save the current plot commands using gnuplot's <code>save</code> command.</p>
713
<th bgcolor="#99ccff"
719
<font color="#000000">
720
<a name="set"></a>
723
<th bgcolor="#99ccff"
728
<font color="#000000">set </font>
733
<font color="#000088"><pre>
738
<p>Set one or more settings at once from keyword arguments.
739
The allowed settings and their treatments are determined from
740
the optiontypes mapping.</p>
741
<table border="0" cellpadding="5" cellspacing="0" width="100%">
744
<th bgcolor="#99ccff"
750
<font color="#000000">
751
<a name="Exceptions">Exceptions</a>
754
<th bgcolor="#99ccff"
759
<font color="#000000"> </font>
765
'option %s is not supported' %( k, )<br>
771
<th bgcolor="#99ccff"
777
<font color="#000000">
778
<a name="set_boolean"></a>
781
<th bgcolor="#99ccff"
786
<font color="#000000">set_boolean </font>
791
<font color="#000088"><pre>
800
<p>Set an on/off option. It is assumed that the way to turn
801
the option on is to type `set <option><code> and to turn it off,
802
`set no<option></code>.</p>
805
<th bgcolor="#99ccff"
811
<font color="#000000">
812
<a name="set_label"></a>
815
<th bgcolor="#99ccff"
820
<font color="#000000">set_label </font>
825
<font color="#000088"><pre>
836
<h3>Set or clear a label option, which can include an offset or font.</h3>
837
<p> If offset is specified, it should be a tuple of two integers
839
<p> If font is specified, it is appended to the command as a
840
string in double quotes. Its interpretation is
841
terminal-dependent; for example, for postscript it might be
842
<code>Helvetica,14</code> for 14 point Helvetica.</p>
845
<th bgcolor="#99ccff"
851
<font color="#000000">
852
<a name="set_range"></a>
855
<th bgcolor="#99ccff"
860
<font color="#000000">set_range </font>
865
<font color="#000088"><pre>
874
<p>Set a range option (xrange, yrange, trange, urange, etc.).
875
The value can be a string (which is passed as-is, without
876
quotes) or a tuple (minrange,maxrange) of numbers or string
877
expressions recognized by gnuplot. If either range is None
878
then that range is passed as `*' (which means to
882
<th bgcolor="#99ccff"
888
<font color="#000000">
889
<a name="set_string"></a>
892
<th bgcolor="#99ccff"
897
<font color="#000000">set_string </font>
902
<font color="#000088"><pre>
911
<p>Set a string option, or if s is omitted, unset the option.</p>
914
<th bgcolor="#99ccff"
920
<font color="#000000">
921
<a name="splot"></a>
924
<th bgcolor="#99ccff"
929
<font color="#000000">splot </font>
934
<font color="#000088"><pre>
943
<h3>Draw a new three-dimensional plot.</h3>
944
<p> Clear the current plot and create a new 3-d plot containing
945
the specified items. Arguments can be of the following types:</p>
947
<dt> <code>PlotItem</code> (e.g., <code>Data</code>, <code>File</code>, <code>Func</code>, <code>GridData</code> )</dt>
949
is the most flexible way to call plot because the
950
PlotItems can contain suboptions. Moreover, PlotItems can
951
be saved to variables so that their lifetime is longer
952
than one plot command--thus they can be replotted with
953
minimal overhead.</dd>
954
<dt> <code>string</code> (e.g., <code>sin(x*y)</code>)</dt>
955
<dd>The string is interpreted as a
956
<code>Func()</code> (a function that is computed by gnuplot).</dd>
957
<dt> Anything else</dt>
958
<dd>The object is converted to a Data() item, and
959
thus plotted as data. Note that each data point should
960
normally have at least three values associated with it
961
(i.e., x, y, and z). If the conversion fails, an
962
exception is raised.</dd>
966
<th bgcolor="#99ccff"
972
<font color="#000000">
973
<a name="title"></a>
976
<th bgcolor="#99ccff"
981
<font color="#000000">title </font>
986
<font color="#000088"><pre>
996
<p>Set the plot's title.</p>
999
<th bgcolor="#99ccff"
1005
<font color="#000000">
1006
<a name="xlabel"></a>
1009
<th bgcolor="#99ccff"
1014
<font color="#000000">xlabel </font>
1019
<font color="#000088"><pre>
1029
<p>Set the plot's xlabel.</p>
1032
<th bgcolor="#99ccff"
1038
<font color="#000000">
1039
<a name="ylabel"></a>
1042
<th bgcolor="#99ccff"
1047
<font color="#000000">ylabel </font>
1052
<font color="#000088"><pre>
1062
<p>Set the plot's ylabel.</p>
1073
<p><i><a href="../../index.html">Table of Contents</a></i></p>
1075
<font size="-2"><i>This document was automatically generated
1076
on Sun Oct 19 17:10:22 2003 by
1077
<a href="http://happydoc.sourceforge.net">HappyDoc</a> version
b'\\ No newline at end of file'