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 |
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 |
3106
|
67 global __multiplot_mode__ = 0; |
|
68 global __multiplot_xsize__; |
|
69 global __multiplot_ysize__; |
|
70 global __multiplot_xn__; |
|
71 global __multiplot_yn__; |
|
72 global __multiplot_xi__; |
|
73 global __multiplot_yi__; |
1540
|
74 |
|
75 if (nargin != 3 && nargin != 1) |
|
76 usage ("subplot (rows, columns, index) or subplot (rcn)"); |
|
77 endif |
|
78 |
|
79 if (nargin == 1) |
|
80 |
1541
|
81 if (! (is_scalar (rows) && rows >= 0)) |
|
82 error ("subplot: input rcn has to be a positive scalar"); |
1540
|
83 endif |
|
84 |
1541
|
85 tmp = rows; |
|
86 index = rem (tmp, 10); |
|
87 tmp = (tmp - index) / 10; |
|
88 columns = rem (tmp, 10); |
|
89 tmp = (tmp - columns) / 10; |
|
90 rows = rem (tmp, 10); |
1540
|
91 |
|
92 elseif (! (is_scalar (columns) && is_scalar (rows) && is_scalar (index))) |
|
93 error ("subplot: columns, rows, and index have to be scalars"); |
|
94 endif |
|
95 |
|
96 columns = round (columns); |
|
97 rows = round (rows); |
|
98 index = round (index); |
|
99 |
|
100 if (index > columns*rows) |
|
101 error ("subplot: index must be less than columns*rows"); |
|
102 endif |
|
103 |
|
104 if (columns < 1 || rows < 1 || index < 1) |
|
105 error ("subplot: columns,rows,index must be be positive"); |
|
106 endif |
|
107 |
|
108 if (columns*rows == 1) |
|
109 |
2303
|
110 ## switching to single plot ? |
1540
|
111 |
3103
|
112 oneplot (); |
1540
|
113 |
3103
|
114 ## XXX FIXME XXX -- do we really need to reset these here? |
1540
|
115 |
3103
|
116 __multiplot_xn__ = 1; |
|
117 __multiplot_yn__ = 1; |
1540
|
118 |
1541
|
119 else |
1540
|
120 |
2303
|
121 ## doing multiplot plots |
1540
|
122 |
3103
|
123 if (! __multiplot_mode__ |
|
124 || __multiplot_xn__ != columns |
|
125 || __multiplot_yn__ != rows) |
1540
|
126 |
3103
|
127 __multiplot_mode__ = 1; |
|
128 __multiplot_xn__ = columns; |
|
129 __multiplot_yn__ = rows; |
|
130 __multiplot_xsize__ = 1.0 ./ columns; |
|
131 __multiplot_ysize__ = 1.0 ./ rows; |
1540
|
132 |
3162
|
133 gnuplot_command_replot = "cle;rep"; |
|
134 |
2520
|
135 gset multiplot; |
1541
|
136 |
3103
|
137 eval (sprintf ("gset size %g, %g", __multiplot_xsize__, |
|
138 __multiplot_ysize__)); |
1541
|
139 endif |
|
140 |
2303
|
141 ## get the sub plot location |
1540
|
142 |
1541
|
143 yp = fix ((index-1)/columns); |
|
144 xp = index - yp*columns - 1; |
3103
|
145 __multiplot_xi__ = ++xp; |
|
146 __multiplot_yi__ = ++yp; |
1540
|
147 |
2303
|
148 ## set the origin |
1541
|
149 |
3103
|
150 xo = (xp - 1.0) * __multiplot_xsize__; |
|
151 yo = (rows - yp) * __multiplot_ysize__; |
1541
|
152 |
2520
|
153 eval (sprintf ("gset origin %g, %g", xo, yo)); |
1540
|
154 |
|
155 endif |
|
156 |
|
157 endfunction |