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 |
|
62 ## +-----+-----+-----+-----+ |
|
63 ## | 1 | 2 | 3 | 4 | |
|
64 ## +-----+-----+-----+-----+ |
|
65 ## | 5 | 6 | 7 | 8 | |
|
66 ## +-----+-----+-----+-----+ |
|
67 ## @end group |
|
68 ## @end display |
|
69 ## @end ifinfo |
5798
|
70 ## @seealso{plot} |
3368
|
71 ## @end deftypefn |
1540
|
72 |
2312
|
73 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU> |
|
74 ## Adapted-By: jwe |
1540
|
75 |
2312
|
76 function subplot (rows, columns, index) |
1540
|
77 |
5493
|
78 __plot_globals__; |
1540
|
79 |
6163
|
80 cf = __current_figure__; |
|
81 |
1540
|
82 if (nargin != 3 && nargin != 1) |
6046
|
83 print_usage (); |
1540
|
84 endif |
|
85 |
|
86 if (nargin == 1) |
|
87 |
4030
|
88 if (! (isscalar (rows) && rows >= 0)) |
1541
|
89 error ("subplot: input rcn has to be a positive scalar"); |
1540
|
90 endif |
|
91 |
1541
|
92 tmp = rows; |
|
93 index = rem (tmp, 10); |
|
94 tmp = (tmp - index) / 10; |
|
95 columns = rem (tmp, 10); |
|
96 tmp = (tmp - columns) / 10; |
|
97 rows = rem (tmp, 10); |
1540
|
98 |
4030
|
99 elseif (! (isscalar (columns) && isscalar (rows) && isscalar (index))) |
1540
|
100 error ("subplot: columns, rows, and index have to be scalars"); |
|
101 endif |
|
102 |
|
103 columns = round (columns); |
|
104 rows = round (rows); |
|
105 index = round (index); |
|
106 |
|
107 if (index > columns*rows) |
|
108 error ("subplot: index must be less than columns*rows"); |
|
109 endif |
|
110 |
|
111 if (columns < 1 || rows < 1 || index < 1) |
|
112 error ("subplot: columns,rows,index must be be positive"); |
|
113 endif |
|
114 |
|
115 if (columns*rows == 1) |
|
116 |
2303
|
117 ## switching to single plot ? |
1540
|
118 |
3103
|
119 oneplot (); |
1540
|
120 |
6163
|
121 __multiplot_xn__(cf) = 1; |
|
122 __multiplot_yn__(cf) = 1; |
1540
|
123 |
1541
|
124 else |
1540
|
125 |
2303
|
126 ## doing multiplot plots |
1540
|
127 |
6163
|
128 if (! __multiplot_mode__(cf) |
|
129 || __multiplot_xn__(cf) != columns |
|
130 || __multiplot_yn__(cf) != rows) |
1540
|
131 |
6163
|
132 __multiplot_mode__(cf) = true; |
|
133 __multiplot_xn__(cf) = columns; |
|
134 __multiplot_yn__(cf) = rows; |
|
135 __multiplot_xsize__(cf) = 1 / columns; |
|
136 __multiplot_ysize__(cf) = 1 / rows; |
1540
|
137 |
5252
|
138 __gnuplot_raw__ ("set multiplot;\n"); |
1541
|
139 |
5252
|
140 __gnuplot_raw__ (sprintf ("set size %g, %g;\n", |
6163
|
141 __multiplot_xsize__(cf), |
|
142 __multiplot_ysize__(cf))); |
1541
|
143 endif |
|
144 |
2303
|
145 ## get the sub plot location |
1540
|
146 |
1541
|
147 yp = fix ((index-1)/columns); |
|
148 xp = index - yp*columns - 1; |
6163
|
149 __multiplot_xi__(cf) = ++xp; |
|
150 __multiplot_yi__(cf) = ++yp; |
1540
|
151 |
2303
|
152 ## set the origin |
1541
|
153 |
6163
|
154 xo = (xp - 1.0) * __multiplot_xsize__(cf); |
|
155 yo = (rows - yp) * __multiplot_ysize__(cf); |
1541
|
156 |
5252
|
157 __gnuplot_raw__ (sprintf ("set origin %g, %g;\n", xo, yo)); |
1540
|
158 |
|
159 endif |
|
160 |
|
161 endfunction |