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 ## |
4503
|
26 ## The global variable @var{__multiplot_scale__} should be used when the |
5215
|
27 ## command @code{__gnuplot_set__ size xsize, ysize} has been used prior to calling |
4503
|
28 ## @code{subplot}. |
|
29 ## |
|
30 ## The value of @var{__multiplot_scale__} should be a vector with two |
|
31 ## elements, the first set equal to @var{xsize} and the second to |
|
32 ## @var{ysize}. |
|
33 ## |
2311
|
34 ## Input: |
3426
|
35 ## |
3368
|
36 ## @table @var |
|
37 ## @item rows |
|
38 ## Number of rows in subplot grid. |
3426
|
39 ## |
3368
|
40 ## @item columns |
|
41 ## Number of columns in subplot grid. |
3426
|
42 ## |
3368
|
43 ## @item index |
|
44 ## Index of subplot where to make the next plot. |
|
45 ## @end table |
3426
|
46 ## |
3368
|
47 ## If only one argument is supplied, then it must be a three digit value |
|
48 ## specifying the location in digits 1 (rows) and 2 (columns) and the plot |
|
49 ## index in digit 3. |
3426
|
50 ## |
3368
|
51 ## The plot index runs row-wise. First all the columns in a row are filled |
|
52 ## and then the next row is filled. |
3426
|
53 ## |
5798
|
54 ## For example, a plot with 2 by 3 grid will have plot indices running as |
2311
|
55 ## follows: |
3368
|
56 ## @iftex |
|
57 ## @tex |
|
58 ## \vskip 10pt |
|
59 ## \hfil\vbox{\offinterlineskip\hrule |
|
60 ## \halign{\vrule#&&\qquad\hfil#\hfil\qquad\vrule\cr |
|
61 ## height13pt&1&2&3&4\cr height12pt&&&&\cr\noalign{\hrule} |
|
62 ## height13pt&5&6&7&8\cr height12pt&&&&\cr\noalign{\hrule}}} |
|
63 ## \hfil |
|
64 ## \vskip 10pt |
|
65 ## @end tex |
|
66 ## @end iftex |
|
67 ## @ifinfo |
|
68 ## @display |
|
69 ## @group |
|
70 ## +-----+-----+-----+-----+ |
|
71 ## | 1 | 2 | 3 | 4 | |
|
72 ## +-----+-----+-----+-----+ |
|
73 ## | 5 | 6 | 7 | 8 | |
|
74 ## +-----+-----+-----+-----+ |
|
75 ## @end group |
|
76 ## @end display |
|
77 ## @end ifinfo |
5798
|
78 ## @seealso{plot} |
3368
|
79 ## @end deftypefn |
1540
|
80 |
2312
|
81 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU> |
|
82 ## Adapted-By: jwe |
1540
|
83 |
2312
|
84 function subplot (rows, columns, index) |
1540
|
85 |
5493
|
86 __plot_globals__; |
1540
|
87 |
|
88 if (nargin != 3 && nargin != 1) |
6046
|
89 print_usage (); |
1540
|
90 endif |
|
91 |
|
92 if (nargin == 1) |
|
93 |
4030
|
94 if (! (isscalar (rows) && rows >= 0)) |
1541
|
95 error ("subplot: input rcn has to be a positive scalar"); |
1540
|
96 endif |
|
97 |
1541
|
98 tmp = rows; |
|
99 index = rem (tmp, 10); |
|
100 tmp = (tmp - index) / 10; |
|
101 columns = rem (tmp, 10); |
|
102 tmp = (tmp - columns) / 10; |
|
103 rows = rem (tmp, 10); |
1540
|
104 |
4030
|
105 elseif (! (isscalar (columns) && isscalar (rows) && isscalar (index))) |
1540
|
106 error ("subplot: columns, rows, and index have to be scalars"); |
|
107 endif |
|
108 |
|
109 columns = round (columns); |
|
110 rows = round (rows); |
|
111 index = round (index); |
|
112 |
|
113 if (index > columns*rows) |
|
114 error ("subplot: index must be less than columns*rows"); |
|
115 endif |
|
116 |
|
117 if (columns < 1 || rows < 1 || index < 1) |
|
118 error ("subplot: columns,rows,index must be be positive"); |
|
119 endif |
|
120 |
|
121 if (columns*rows == 1) |
|
122 |
2303
|
123 ## switching to single plot ? |
1540
|
124 |
3103
|
125 oneplot (); |
1540
|
126 |
5775
|
127 ## FIXME -- do we really need to reset these here? |
1540
|
128 |
3103
|
129 __multiplot_xn__ = 1; |
|
130 __multiplot_yn__ = 1; |
1540
|
131 |
1541
|
132 else |
1540
|
133 |
2303
|
134 ## doing multiplot plots |
1540
|
135 |
3103
|
136 if (! __multiplot_mode__ |
3426
|
137 || __multiplot_xn__ != columns |
|
138 || __multiplot_yn__ != rows) |
1540
|
139 |
3103
|
140 __multiplot_mode__ = 1; |
|
141 __multiplot_xn__ = columns; |
|
142 __multiplot_yn__ = rows; |
4503
|
143 __multiplot_xsize__ = __multiplot_scale__(1) ./ columns; |
|
144 __multiplot_ysize__ = __multiplot_scale__(2) ./ rows; |
1540
|
145 |
5252
|
146 __gnuplot_raw__ ("set multiplot;\n"); |
1541
|
147 |
5252
|
148 __gnuplot_raw__ (sprintf ("set size %g, %g;\n", |
|
149 __multiplot_xsize__, __multiplot_ysize__)); |
1541
|
150 endif |
|
151 |
2303
|
152 ## get the sub plot location |
1540
|
153 |
1541
|
154 yp = fix ((index-1)/columns); |
|
155 xp = index - yp*columns - 1; |
3103
|
156 __multiplot_xi__ = ++xp; |
|
157 __multiplot_yi__ = ++yp; |
1540
|
158 |
2303
|
159 ## set the origin |
1541
|
160 |
3103
|
161 xo = (xp - 1.0) * __multiplot_xsize__; |
|
162 yo = (rows - yp) * __multiplot_ysize__; |
1541
|
163 |
5252
|
164 __gnuplot_raw__ (sprintf ("set origin %g, %g;\n", xo, yo)); |
1540
|
165 |
|
166 endif |
|
167 |
|
168 endfunction |