Mercurial > hg > octave-lyh
annotate scripts/plot/subplot.m @ 8350:0e3a92a8683c
fix texi bug in subplot.m
author | Thorsten Meyer <thorsten.meyier@gmx.de> |
---|---|
date | Wed, 05 Nov 2008 17:51:42 +0100 |
parents | c6e9ff62c64a |
children | 81d6ab3ac93c |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2005, |
2 ## 2006, 2007 John W. Eaton | |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
1540 | 19 |
3368 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} subplot (@var{rows}, @var{cols}, @var{index}) | |
22 ## @deftypefnx {Function File} {} subplot (@var{rcn}) | |
6448 | 23 ## Set up a plot grid with @var{cols} by @var{rows} subwindows and plot |
24 ## in location given by @var{index}. | |
3426 | 25 ## |
3368 | 26 ## If only one argument is supplied, then it must be a three digit value |
27 ## specifying the location in digits 1 (rows) and 2 (columns) and the plot | |
28 ## index in digit 3. | |
3426 | 29 ## |
3368 | 30 ## The plot index runs row-wise. First all the columns in a row are filled |
31 ## and then the next row is filled. | |
3426 | 32 ## |
5798 | 33 ## For example, a plot with 2 by 3 grid will have plot indices running as |
2311 | 34 ## follows: |
3368 | 35 ## @iftex |
36 ## @tex | |
37 ## \vskip 10pt | |
38 ## \hfil\vbox{\offinterlineskip\hrule | |
39 ## \halign{\vrule#&&\qquad\hfil#\hfil\qquad\vrule\cr | |
7107 | 40 ## height13pt&1&2&3\cr height12pt&&&\cr\noalign{\hrule} |
41 ## height13pt&4&5&6\cr height12pt&&&\cr\noalign{\hrule}}} | |
3368 | 42 ## \hfil |
43 ## \vskip 10pt | |
44 ## @end tex | |
45 ## @end iftex | |
46 ## @ifinfo | |
47 ## @display | |
8350
0e3a92a8683c
fix texi bug in subplot.m
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8232
diff
changeset
|
48 ## @example |
3368 | 49 ## @group |
6257 | 50 ## |
7040 | 51 ## +-----+-----+-----+ |
52 ## | 1 | 2 | 3 | | |
53 ## +-----+-----+-----+ | |
54 ## | 4 | 5 | 6 | | |
55 ## +-----+-----+-----+ | |
8350
0e3a92a8683c
fix texi bug in subplot.m
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8232
diff
changeset
|
56 ## @end group |
6257 | 57 ## @end example |
3368 | 58 ## @end display |
59 ## @end ifinfo | |
5798 | 60 ## @seealso{plot} |
3368 | 61 ## @end deftypefn |
1540 | 62 |
2312 | 63 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU> |
64 ## Adapted-By: jwe | |
1540 | 65 |
6257 | 66 function h = subplot (rows, columns, index) |
6163 | 67 |
1540 | 68 if (nargin != 3 && nargin != 1) |
6046 | 69 print_usage (); |
1540 | 70 endif |
71 | |
72 if (nargin == 1) | |
73 | |
4030 | 74 if (! (isscalar (rows) && rows >= 0)) |
1541 | 75 error ("subplot: input rcn has to be a positive scalar"); |
1540 | 76 endif |
77 | |
1541 | 78 tmp = rows; |
79 index = rem (tmp, 10); | |
80 tmp = (tmp - index) / 10; | |
81 columns = rem (tmp, 10); | |
82 tmp = (tmp - columns) / 10; | |
83 rows = rem (tmp, 10); | |
1540 | 84 |
4030 | 85 elseif (! (isscalar (columns) && isscalar (rows) && isscalar (index))) |
1540 | 86 error ("subplot: columns, rows, and index have to be scalars"); |
87 endif | |
88 | |
89 columns = round (columns); | |
90 rows = round (rows); | |
91 index = round (index); | |
92 | |
93 if (index > columns*rows) | |
94 error ("subplot: index must be less than columns*rows"); | |
95 endif | |
96 | |
97 if (columns < 1 || rows < 1 || index < 1) | |
98 error ("subplot: columns,rows,index must be be positive"); | |
99 endif | |
100 | |
6257 | 101 xsize = 1 / columns; |
102 ysize = 1 / rows; | |
1540 | 103 |
6257 | 104 yp = fix ((index-1)/columns); |
105 xp = index - yp*columns - 1; | |
1540 | 106 |
6425 | 107 x0 = xp * xsize; |
108 y0 = (rows - yp - 1) * ysize; | |
1540 | 109 |
6425 | 110 pos = [x0, y0, xsize, ysize]; |
111 | |
112 x1 = x0 + xsize; | |
113 y1 = y0 + ysize; | |
6257 | 114 |
115 cf = gcf (); | |
1540 | 116 |
6257 | 117 set (cf, "nextplot", "add"); |
1540 | 118 |
6257 | 119 found = false; |
8232
c6e9ff62c64a
Fix subplot for column vector of children in figure
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
120 kids = get (cf, "children"); |
c6e9ff62c64a
Fix subplot for column vector of children in figure
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
121 for child = reshape (kids, 1, numel (kids)) |
7086 | 122 ## Check whether this child is still valid; this might not be the |
123 ## case anymore due to the deletion of previous children (due to | |
124 ## "deletefcn" callback or for legends/colorbars that are deleted | |
125 ## with their corresponding axes). | |
6765 | 126 if (! ishandle (child)) |
127 continue; | |
128 endif | |
6828 | 129 if (strcmp (get (child, "type"), "axes")) |
8208 | 130 ## Skip legend and colorbar objects. |
131 if (strcmp (get (child, "tag"), "legend") || | |
132 strcmp (get (child, "tag"), "colorbar")) | |
7086 | 133 continue; |
134 endif | |
6828 | 135 objpos = get (child, "outerposition"); |
6425 | 136 if (objpos == pos) |
137 ## If the new axes are in exactly the same position as an | |
138 ## existing axes object, use the existing axes. | |
6257 | 139 found = true; |
140 tmp = child; | |
6425 | 141 else |
142 ## If the new axes overlap an old axes object, delete the old | |
143 ## axes. | |
144 objx0 = objpos(1); | |
145 objx1 = objx0 + objpos(3); | |
146 objy0 = objpos(2); | |
147 objy1 = objy0 + objpos(4); | |
148 if (! (x0 >= objx1 || x1 <= objx0 || y0 >= objy1 || y1 <= objy0)) | |
149 delete (child); | |
150 endif | |
6178 | 151 endif |
1541 | 152 endif |
6257 | 153 endfor |
1540 | 154 |
6424 | 155 if (found) |
156 set (cf, "currentaxes", tmp); | |
157 else | |
8208 | 158 border = [0.130, 0.110, 0.225, 0.185] .* [xsize, ysize, xsize, ysize]; |
159 pos2 = [pos(1:2) + border(1:2), pos(3:4) - border(1:2) - border(3:4)]; | |
160 tmp = axes ("outerposition", pos, "position", pos2); | |
6257 | 161 endif |
1540 | 162 |
6257 | 163 if (nargout > 0) |
164 h = tmp; | |
1540 | 165 endif |
166 | |
167 endfunction |