2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
1540
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} subplot (@var{rows}, @var{cols}, @var{index}) |
|
22 ## @deftypefnx {Function File} {} subplot (@var{rcn}) |
|
23 ## Sets @code{gnuplot} in multiplot mode and plots in location |
|
24 ## given by index (there are @var{cols} by @var{rows} subwindows). |
3426
|
25 ## |
2311
|
26 ## Input: |
3426
|
27 ## |
3368
|
28 ## @table @var |
|
29 ## @item rows |
|
30 ## Number of rows in subplot grid. |
3426
|
31 ## |
3368
|
32 ## @item columns |
|
33 ## Number of columns in subplot grid. |
3426
|
34 ## |
3368
|
35 ## @item index |
|
36 ## Index of subplot where to make the next plot. |
|
37 ## @end table |
3426
|
38 ## |
3368
|
39 ## If only one argument is supplied, then it must be a three digit value |
|
40 ## specifying the location in digits 1 (rows) and 2 (columns) and the plot |
|
41 ## index in digit 3. |
3426
|
42 ## |
3368
|
43 ## The plot index runs row-wise. First all the columns in a row are filled |
|
44 ## and then the next row is filled. |
3426
|
45 ## |
5798
|
46 ## For example, a plot with 2 by 3 grid will have plot indices running as |
2311
|
47 ## follows: |
3368
|
48 ## @iftex |
|
49 ## @tex |
|
50 ## \vskip 10pt |
|
51 ## \hfil\vbox{\offinterlineskip\hrule |
|
52 ## \halign{\vrule#&&\qquad\hfil#\hfil\qquad\vrule\cr |
|
53 ## height13pt&1&2&3&4\cr height12pt&&&&\cr\noalign{\hrule} |
|
54 ## height13pt&5&6&7&8\cr height12pt&&&&\cr\noalign{\hrule}}} |
|
55 ## \hfil |
|
56 ## \vskip 10pt |
|
57 ## @end tex |
|
58 ## @end iftex |
|
59 ## @ifinfo |
|
60 ## @display |
|
61 ## @group |
6257
|
62 ## @example |
|
63 ## |
3368
|
64 ## +-----+-----+-----+-----+ |
|
65 ## | 1 | 2 | 3 | 4 | |
|
66 ## +-----+-----+-----+-----+ |
|
67 ## | 5 | 6 | 7 | 8 | |
|
68 ## +-----+-----+-----+-----+ |
6257
|
69 ## @end example |
3368
|
70 ## @end group |
|
71 ## @end display |
|
72 ## @end ifinfo |
5798
|
73 ## @seealso{plot} |
3368
|
74 ## @end deftypefn |
1540
|
75 |
2312
|
76 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU> |
|
77 ## Adapted-By: jwe |
1540
|
78 |
6257
|
79 function h = subplot (rows, columns, index) |
6163
|
80 |
1540
|
81 if (nargin != 3 && nargin != 1) |
6046
|
82 print_usage (); |
1540
|
83 endif |
|
84 |
|
85 if (nargin == 1) |
|
86 |
4030
|
87 if (! (isscalar (rows) && rows >= 0)) |
1541
|
88 error ("subplot: input rcn has to be a positive scalar"); |
1540
|
89 endif |
|
90 |
1541
|
91 tmp = rows; |
|
92 index = rem (tmp, 10); |
|
93 tmp = (tmp - index) / 10; |
|
94 columns = rem (tmp, 10); |
|
95 tmp = (tmp - columns) / 10; |
|
96 rows = rem (tmp, 10); |
1540
|
97 |
4030
|
98 elseif (! (isscalar (columns) && isscalar (rows) && isscalar (index))) |
1540
|
99 error ("subplot: columns, rows, and index have to be scalars"); |
|
100 endif |
|
101 |
|
102 columns = round (columns); |
|
103 rows = round (rows); |
|
104 index = round (index); |
|
105 |
|
106 if (index > columns*rows) |
|
107 error ("subplot: index must be less than columns*rows"); |
|
108 endif |
|
109 |
|
110 if (columns < 1 || rows < 1 || index < 1) |
|
111 error ("subplot: columns,rows,index must be be positive"); |
|
112 endif |
|
113 |
6257
|
114 xsize = 1 / columns; |
|
115 ysize = 1 / rows; |
1540
|
116 |
6257
|
117 yp = fix ((index-1)/columns); |
|
118 xp = index - yp*columns - 1; |
1540
|
119 |
6257
|
120 xorigin = xp * xsize; |
|
121 yorigin = (rows - yp - 1) * ysize; |
1540
|
122 |
6257
|
123 pos = [xorigin, yorigin, xsize, ysize]; |
|
124 |
|
125 cf = gcf (); |
1540
|
126 |
6257
|
127 set (cf, "nextplot", "add"); |
1540
|
128 |
6257
|
129 obj = get (cf); |
1540
|
130 |
6257
|
131 found = false; |
|
132 for child = obj.children |
|
133 obj = get (child); |
|
134 if (strcmp (obj.type, "axes")) |
|
135 if (obj.outerposition == pos) |
|
136 found = true; |
|
137 tmp = child; |
|
138 break; |
6178
|
139 endif |
1541
|
140 endif |
6257
|
141 endfor |
1540
|
142 |
6424
|
143 if (found) |
|
144 set (cf, "currentaxes", tmp); |
|
145 else |
6257
|
146 tmp = axes ("outerposition", pos); |
|
147 endif |
1540
|
148 |
6257
|
149 if (nargout > 0) |
|
150 h = tmp; |
1540
|
151 endif |
|
152 |
|
153 endfunction |