annotate scripts/plot/subplot.m @ 3233:98d0ee053ba4

[project @ 1999-01-27 20:23:40 by jwe]
author jwe
date Wed, 27 Jan 1999 20:23:46 +0000
parents 7c96e85c76db
children a4cd1e9d9962
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2520
diff changeset
1 ## Copyright (C) 1996, 1997 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## under the terms of the GNU General Public License as published by
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
7 ## the Free Software Foundation; either version 2, or (at your option)
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
8 ## any later version.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ## You should have received a copy of the GNU General Public License
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
18 ## 02111-1307, USA.
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
19
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
20 ## usage: subplot (rows, columns, index)
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
21 ## subplot (rcn)
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
22 ##
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
23 ## NOTE: this will work only with gnuplot installed with
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
24 ## multiplot patch (or version 3.6 beta)
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
25 ##
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
26 ## Sets gnuplot in multiplot mode and plots in location
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
27 ## given by index (there are columns X rows subwindows)
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
28 ##
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
29 ## Input:
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
30 ##
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
31 ## rows : number of rows in subplot grid
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
32 ## columns: number of columns in subplot grid
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
33 ## index : index of subplot where to make the next plot
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
34 ##
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
35 ## If only one arg, then it (crn) has to be three digit value
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
36 ## specifying the location in digit 1 (rows) and 2 (columns) and digit
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
37 ## 3 is the plot index
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
38 ##
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
39 ## The plot index runs row-wise,i.e., first all the columns in a row
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
40 ## are filled and then the next row is filled
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
41 ##
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
42 ## For example, plot with 4 X 2 grid, will have plot indices running as
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
43 ## follows:
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
44 ##
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
45 ## -----------------------------------
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
46 ## | | | | |
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
47 ## | 1 | 2 | 3 | 4 |
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
48 ## | | | | |
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
49 ## -----------------------------------
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
50 ## | | | | |
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
51 ## | 5 | 6 | 7 | 8 |
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
52 ## | | | | |
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
53 ## -----------------------------------
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
54 ##
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
55
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
56 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
57 ## Adapted-By: jwe
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
58
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
59 function subplot (rows, columns, index)
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
60
2296
5f6c19054139 [project @ 1996-06-14 06:41:57 by jwe]
jwe
parents: 1887
diff changeset
61 if (! gnuplot_has_multiplot)
5f6c19054139 [project @ 1996-06-14 06:41:57 by jwe]
jwe
parents: 1887
diff changeset
62 error ("subplot: gnuplot does not appear to support this feature");
5f6c19054139 [project @ 1996-06-14 06:41:57 by jwe]
jwe
parents: 1887
diff changeset
63 endif
5f6c19054139 [project @ 1996-06-14 06:41:57 by jwe]
jwe
parents: 1887
diff changeset
64
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2296
diff changeset
65 ## global variables to keep track of multiplot options
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
66
3106
21208b797332 [project @ 1997-11-19 06:26:03 by jwe]
jwe
parents: 3103
diff changeset
67 global __multiplot_mode__ = 0;
21208b797332 [project @ 1997-11-19 06:26:03 by jwe]
jwe
parents: 3103
diff changeset
68 global __multiplot_xsize__;
21208b797332 [project @ 1997-11-19 06:26:03 by jwe]
jwe
parents: 3103
diff changeset
69 global __multiplot_ysize__;
21208b797332 [project @ 1997-11-19 06:26:03 by jwe]
jwe
parents: 3103
diff changeset
70 global __multiplot_xn__;
21208b797332 [project @ 1997-11-19 06:26:03 by jwe]
jwe
parents: 3103
diff changeset
71 global __multiplot_yn__;
21208b797332 [project @ 1997-11-19 06:26:03 by jwe]
jwe
parents: 3103
diff changeset
72 global __multiplot_xi__;
21208b797332 [project @ 1997-11-19 06:26:03 by jwe]
jwe
parents: 3103
diff changeset
73 global __multiplot_yi__;
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
74
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
75 if (nargin != 3 && nargin != 1)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
76 usage ("subplot (rows, columns, index) or subplot (rcn)");
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
77 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
78
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
79 if (nargin == 1)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
80
1541
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
81 if (! (is_scalar (rows) && rows >= 0))
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
82 error ("subplot: input rcn has to be a positive scalar");
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
83 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
84
1541
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
85 tmp = rows;
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
86 index = rem (tmp, 10);
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
87 tmp = (tmp - index) / 10;
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
88 columns = rem (tmp, 10);
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
89 tmp = (tmp - columns) / 10;
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
90 rows = rem (tmp, 10);
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
91
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
92 elseif (! (is_scalar (columns) && is_scalar (rows) && is_scalar (index)))
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
93 error ("subplot: columns, rows, and index have to be scalars");
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
94 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
95
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
96 columns = round (columns);
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
97 rows = round (rows);
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
98 index = round (index);
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
99
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
100 if (index > columns*rows)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
101 error ("subplot: index must be less than columns*rows");
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
102 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
103
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
104 if (columns < 1 || rows < 1 || index < 1)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
105 error ("subplot: columns,rows,index must be be positive");
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
106 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
107
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
108 if (columns*rows == 1)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
109
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2296
diff changeset
110 ## switching to single plot ?
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
111
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
112 oneplot ();
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
113
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
114 ## XXX FIXME XXX -- do we really need to reset these here?
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
115
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
116 __multiplot_xn__ = 1;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
117 __multiplot_yn__ = 1;
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
118
1541
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
119 else
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
120
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2296
diff changeset
121 ## doing multiplot plots
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
122
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
123 if (! __multiplot_mode__
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
124 || __multiplot_xn__ != columns
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
125 || __multiplot_yn__ != rows)
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
126
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
127 __multiplot_mode__ = 1;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
128 __multiplot_xn__ = columns;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
129 __multiplot_yn__ = rows;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
130 __multiplot_xsize__ = 1.0 ./ columns;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
131 __multiplot_ysize__ = 1.0 ./ rows;
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
132
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3156
diff changeset
133 gnuplot_command_replot = "cle;rep";
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3156
diff changeset
134
2520
a034dcdbc282 [project @ 1996-11-15 04:57:21 by jwe]
jwe
parents: 2360
diff changeset
135 gset multiplot;
1541
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
136
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
137 eval (sprintf ("gset size %g, %g", __multiplot_xsize__,
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
138 __multiplot_ysize__));
1541
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
139 endif
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
140
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2296
diff changeset
141 ## get the sub plot location
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
142
1541
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
143 yp = fix ((index-1)/columns);
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
144 xp = index - yp*columns - 1;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
145 __multiplot_xi__ = ++xp;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
146 __multiplot_yi__ = ++yp;
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
147
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2296
diff changeset
148 ## set the origin
1541
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
149
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
150 xo = (xp - 1.0) * __multiplot_xsize__;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 2847
diff changeset
151 yo = (rows - yp) * __multiplot_ysize__;
1541
47bd45a30dda [project @ 1995-10-06 03:40:11 by jwe]
jwe
parents: 1540
diff changeset
152
2520
a034dcdbc282 [project @ 1996-11-15 04:57:21 by jwe]
jwe
parents: 2360
diff changeset
153 eval (sprintf ("gset origin %g, %g", xo, yo));
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
154
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
155 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
156
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
157 endfunction