2313
|
1 ## Copyright (C) 1996 John W. Eaton |
|
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 |
2311
|
20 ## usage: subplot (rows, columns, index) |
|
21 ## subplot (rcn) |
|
22 ## |
|
23 ## NOTE: this will work only with gnuplot installed with |
|
24 ## multiplot patch (or version 3.6 beta) |
|
25 ## |
|
26 ## Sets gnuplot in multiplot mode and plots in location |
|
27 ## given by index (there are columns X rows subwindows) |
|
28 ## |
|
29 ## Input: |
|
30 ## |
|
31 ## rows : number of rows in subplot grid |
|
32 ## columns: number of columns in subplot grid |
|
33 ## index : index of subplot where to make the next plot |
|
34 ## |
|
35 ## If only one arg, then it (crn) has to be three digit value |
|
36 ## specifying the location in digit 1 (rows) and 2 (columns) and digit |
|
37 ## 3 is the plot index |
|
38 ## |
|
39 ## The plot index runs row-wise,i.e., first all the columns in a row |
|
40 ## are filled and then the next row is filled |
|
41 ## |
|
42 ## For example, plot with 4 X 2 grid, will have plot indices running as |
|
43 ## follows: |
|
44 ## |
|
45 ## ----------------------------------- |
|
46 ## | | | | | |
|
47 ## | 1 | 2 | 3 | 4 | |
|
48 ## | | | | | |
|
49 ## ----------------------------------- |
|
50 ## | | | | | |
|
51 ## | 5 | 6 | 7 | 8 | |
|
52 ## | | | | | |
|
53 ## ----------------------------------- |
|
54 ## |
1540
|
55 |
2312
|
56 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU> |
|
57 ## Adapted-By: jwe |
1540
|
58 |
2312
|
59 function subplot (rows, columns, index) |
1540
|
60 |
2296
|
61 if (! gnuplot_has_multiplot) |
|
62 error ("subplot: gnuplot does not appear to support this feature"); |
|
63 endif |
|
64 |
2303
|
65 ## global variables to keep track of multiplot options |
1540
|
66 |
|
67 global multiplot_mode |
1541
|
68 global multiplot_xsize multiplot_ysize |
|
69 global multiplot_xn multiplot_yn |
|
70 global multiplot_xi multiplot_yi |
1540
|
71 |
2303
|
72 ## This is a real kludge. We gnuplot should be made so that replot can |
|
73 ## be executed while doing multiple plots... |
1540
|
74 |
|
75 global multiplot_save_auto_replot = automatic_replot |
|
76 |
|
77 if (nargin != 3 && nargin != 1) |
|
78 usage ("subplot (rows, columns, index) or subplot (rcn)"); |
|
79 endif |
|
80 |
|
81 if ((isstr (automatic_replot) && strcmp (automatic_replot, "true")) |
2296
|
82 || automatic_replot) |
1540
|
83 warning ("turning off automatic replot for multiplot mode"); |
|
84 multiplot_save_auto_replot = automatic_replot; |
|
85 automatic_replot = 0; |
|
86 endif |
|
87 |
|
88 if (nargin == 1) |
|
89 |
1541
|
90 if (! (is_scalar (rows) && rows >= 0)) |
|
91 error ("subplot: input rcn has to be a positive scalar"); |
1540
|
92 endif |
|
93 |
1541
|
94 tmp = rows; |
|
95 index = rem (tmp, 10); |
|
96 tmp = (tmp - index) / 10; |
|
97 columns = rem (tmp, 10); |
|
98 tmp = (tmp - columns) / 10; |
|
99 rows = rem (tmp, 10); |
1540
|
100 |
|
101 elseif (! (is_scalar (columns) && is_scalar (rows) && is_scalar (index))) |
|
102 error ("subplot: columns, rows, and index have to be scalars"); |
|
103 endif |
|
104 |
|
105 columns = round (columns); |
|
106 rows = round (rows); |
|
107 index = round (index); |
|
108 |
|
109 if (index > columns*rows) |
|
110 error ("subplot: index must be less than columns*rows"); |
|
111 endif |
|
112 |
|
113 if (columns < 1 || rows < 1 || index < 1) |
|
114 error ("subplot: columns,rows,index must be be positive"); |
|
115 endif |
|
116 |
|
117 if (columns*rows == 1) |
|
118 |
2303
|
119 ## switching to single plot ? |
1540
|
120 |
|
121 set nomultiplot; |
1557
|
122 set size 1, 1; |
|
123 set origin 0, 0; |
1540
|
124 |
1541
|
125 multiplot_xn = 1; |
|
126 multiplot_yn = 1; |
1540
|
127 multiplot_mode = 0; |
|
128 |
2303
|
129 ## Someone may have reset it betweeen calls... |
1540
|
130 |
|
131 if (! isstr (automatic_replot) && ! automatic_replot) |
|
132 automatic_replot = multiplot_save_auto_replot; |
|
133 endif |
|
134 |
1541
|
135 else |
1540
|
136 |
2303
|
137 ## doing multiplot plots |
1540
|
138 |
1541
|
139 doagain = 0; |
1540
|
140 |
1541
|
141 if (exist ("multiplot_mode") != 1) |
|
142 doagain = 1; |
|
143 elseif (multiplot_mode != 1 || multiplot_xn != columns |
|
144 || multiplot_yn != rows) |
|
145 doagain = 1; |
|
146 endif |
1540
|
147 |
1541
|
148 if (doagain) |
|
149 |
|
150 multiplot_mode = 1; |
|
151 multiplot_xn = columns; |
|
152 multiplot_yn = rows; |
|
153 multiplot_xsize = 1.0 ./ columns; |
|
154 multiplot_ysize = 1.0 ./ rows; |
1540
|
155 |
1541
|
156 set multiplot; |
|
157 |
|
158 eval (sprintf ("set size %g, %g", multiplot_xsize, multiplot_ysize)); |
|
159 |
|
160 endif |
|
161 |
2303
|
162 ## get the sub plot location |
1540
|
163 |
1541
|
164 yp = fix ((index-1)/columns); |
|
165 xp = index - yp*columns - 1; |
|
166 multiplot_xi = ++xp; |
|
167 multiplot_yi = ++yp; |
1540
|
168 |
2303
|
169 ## set the origin |
1541
|
170 |
|
171 xo = (xp - 1.0)*multiplot_xsize; |
|
172 yo = (rows - yp)*multiplot_ysize; |
|
173 |
|
174 eval (sprintf ("set origin %g, %g", xo, yo)); |
1540
|
175 |
|
176 endif |
|
177 |
|
178 endfunction |