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 |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, 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 ## |
3368
|
46 ## For example, a plot with 4 by 2 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 |
|
70 ## @end deftypefn |
1540
|
71 |
2312
|
72 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU> |
|
73 ## Adapted-By: jwe |
1540
|
74 |
2312
|
75 function subplot (rows, columns, index) |
1540
|
76 |
2296
|
77 if (! gnuplot_has_multiplot) |
|
78 error ("subplot: gnuplot does not appear to support this feature"); |
|
79 endif |
|
80 |
2303
|
81 ## global variables to keep track of multiplot options |
1540
|
82 |
3106
|
83 global __multiplot_mode__ = 0; |
|
84 global __multiplot_xsize__; |
|
85 global __multiplot_ysize__; |
|
86 global __multiplot_xn__; |
|
87 global __multiplot_yn__; |
|
88 global __multiplot_xi__; |
|
89 global __multiplot_yi__; |
1540
|
90 |
|
91 if (nargin != 3 && nargin != 1) |
|
92 usage ("subplot (rows, columns, index) or subplot (rcn)"); |
|
93 endif |
|
94 |
|
95 if (nargin == 1) |
|
96 |
4030
|
97 if (! (isscalar (rows) && rows >= 0)) |
1541
|
98 error ("subplot: input rcn has to be a positive scalar"); |
1540
|
99 endif |
|
100 |
1541
|
101 tmp = rows; |
|
102 index = rem (tmp, 10); |
|
103 tmp = (tmp - index) / 10; |
|
104 columns = rem (tmp, 10); |
|
105 tmp = (tmp - columns) / 10; |
|
106 rows = rem (tmp, 10); |
1540
|
107 |
4030
|
108 elseif (! (isscalar (columns) && isscalar (rows) && isscalar (index))) |
1540
|
109 error ("subplot: columns, rows, and index have to be scalars"); |
|
110 endif |
|
111 |
|
112 columns = round (columns); |
|
113 rows = round (rows); |
|
114 index = round (index); |
|
115 |
|
116 if (index > columns*rows) |
|
117 error ("subplot: index must be less than columns*rows"); |
|
118 endif |
|
119 |
|
120 if (columns < 1 || rows < 1 || index < 1) |
|
121 error ("subplot: columns,rows,index must be be positive"); |
|
122 endif |
|
123 |
|
124 if (columns*rows == 1) |
|
125 |
2303
|
126 ## switching to single plot ? |
1540
|
127 |
3103
|
128 oneplot (); |
1540
|
129 |
3103
|
130 ## XXX FIXME XXX -- do we really need to reset these here? |
1540
|
131 |
3103
|
132 __multiplot_xn__ = 1; |
|
133 __multiplot_yn__ = 1; |
1540
|
134 |
1541
|
135 else |
1540
|
136 |
2303
|
137 ## doing multiplot plots |
1540
|
138 |
3103
|
139 if (! __multiplot_mode__ |
3426
|
140 || __multiplot_xn__ != columns |
|
141 || __multiplot_yn__ != rows) |
1540
|
142 |
3103
|
143 __multiplot_mode__ = 1; |
|
144 __multiplot_xn__ = columns; |
|
145 __multiplot_yn__ = rows; |
|
146 __multiplot_xsize__ = 1.0 ./ columns; |
|
147 __multiplot_ysize__ = 1.0 ./ rows; |
1540
|
148 |
3162
|
149 gnuplot_command_replot = "cle;rep"; |
|
150 |
2520
|
151 gset multiplot; |
1541
|
152 |
3103
|
153 eval (sprintf ("gset size %g, %g", __multiplot_xsize__, |
3426
|
154 __multiplot_ysize__)); |
1541
|
155 endif |
|
156 |
2303
|
157 ## get the sub plot location |
1540
|
158 |
1541
|
159 yp = fix ((index-1)/columns); |
|
160 xp = index - yp*columns - 1; |
3103
|
161 __multiplot_xi__ = ++xp; |
|
162 __multiplot_yi__ = ++yp; |
1540
|
163 |
2303
|
164 ## set the origin |
1541
|
165 |
3103
|
166 xo = (xp - 1.0) * __multiplot_xsize__; |
|
167 yo = (rows - yp) * __multiplot_ysize__; |
1541
|
168 |
2520
|
169 eval (sprintf ("gset origin %g, %g", xo, yo)); |
1540
|
170 |
|
171 endif |
|
172 |
|
173 endfunction |