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