Mercurial > hg > octave-nkf
annotate scripts/plot/subplot.m @ 8890:ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sat, 28 Feb 2009 22:39:33 -0500 |
parents | 995f8b064b32 |
children | eb63fbe60fab |
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 | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8350
diff
changeset
|
46 ## @ifnottex |
3368 | 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 |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8350
diff
changeset
|
59 ## @end ifnottex |
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 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
85 elseif (! (isscalar (columns) && isscalar (rows))) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
86 error ("subplot: columns, and rows must be scalars"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
87 elseif (any (index < 1) || any (index > rows*columns)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
88 error ("subplot: index value must be greater than 1 and less than rows*columns") |
1540 | 89 endif |
90 | |
91 columns = round (columns); | |
92 rows = round (rows); | |
93 index = round (index); | |
94 | |
95 if (index > columns*rows) | |
96 error ("subplot: index must be less than columns*rows"); | |
97 endif | |
98 | |
99 if (columns < 1 || rows < 1 || index < 1) | |
100 error ("subplot: columns,rows,index must be be positive"); | |
101 endif | |
102 | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
103 units = get (0, "defaultaxesunits"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
104 unwind_protect |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
105 set (0, "defaultaxesunits", "normalized") |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
106 pos = subplot_position (rows, columns, index, "position", units); |
1540 | 107 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
108 cf = gcf (); |
6425 | 109 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
110 set (cf, "nextplot", "add"); |
1540 | 111 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
112 found = false; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
113 kids = get (cf, "children"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
114 for child = reshape (kids, 1, numel (kids)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
115 ## Check whether this child is still valid; this might not be the |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
116 ## case anymore due to the deletion of previous children (due to |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
117 ## "deletefcn" callback or for legends/colorbars that are deleted |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
118 ## with their corresponding axes). |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
119 if (! ishandle (child)) |
7086 | 120 continue; |
121 endif | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
122 if (strcmp (get (child, "type"), "axes")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
123 ## Skip legend and colorbar objects. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
124 if (strcmp (get (child, "tag"), "legend") || |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
125 strcmp (get (child, "tag"), "colorbar")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
126 continue; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
127 endif |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
128 objpos = get (child, "position"); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
129 if (all (objpos == pos)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
130 ## If the new axes are in exactly the same position as an |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
131 ## existing axes object, use the existing axes. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
132 found = true; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
133 tmp = child; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
134 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
135 ## If the new axes overlap an old axes object, delete the old |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
136 ## axes. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
137 x0 = pos(1); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
138 x1 = x0 + pos(3); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
139 y0 = pos(2); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
140 y1 = y0 + pos(4); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
141 objx0 = objpos(1); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
142 objx1 = objx0 + objpos(3); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
143 objy0 = objpos(2); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
144 objy1 = objy0 + objpos(4); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
145 if (! (x0 >= objx1 || x1 <= objx0 || y0 >= objy1 || y1 <= objy0)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
146 delete (child); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
147 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
148 endif |
6178 | 149 endif |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
150 endfor |
1540 | 151 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
152 if (found) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
153 set (cf, "currentaxes", tmp); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
154 else |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
155 pos = subplot_position (rows, columns, index, "outerposition", units); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
156 pos2 = subplot_position (rows, columns, index, "position", units); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
157 tmp = axes ("outerposition", pos, "position", pos2); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
158 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
159 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
160 unwind_protect_cleanup |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
161 set (0, "defaultaxesunits", units); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
162 end_unwind_protect |
1540 | 163 |
6257 | 164 if (nargout > 0) |
165 h = tmp; | |
1540 | 166 endif |
167 | |
168 endfunction | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
169 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
170 function pos = subplot_position (rows, columns, index, position_property, units) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
171 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
172 ## For 1 row and 1 column return the usual default. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
173 if (rows == 1 && columns == 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
174 if (strcmpi (position_property, "position")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
175 pos = get (0, "defaultaxesposition"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
176 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
177 pos = get (0, "defaultaxesouterposition"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
178 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
179 return |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
180 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
181 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
182 ## This produces compatible behavior for the "position" property. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
183 margins.left = 0.130; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
184 margins.right = 0.095; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
185 margins.top = 0.075; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
186 margins.bottom = 0.110; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
187 pc = 1 ./ [0.1860, (margins.left + margins.right - 1)]; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
188 margins.column = 1 ./ polyval (pc , columns); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
189 pr = 1 ./ [0.2282, (margins.top + margins.bottom - 1)]; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
190 margins.row = 1 ./ polyval (pr , rows); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
191 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
192 ## Calculate the width/height of the subplot axes. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
193 width = 1 - margins.left - margins.right - (columns-1)*margins.column; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
194 width = width / columns; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
195 height = 1 - margins.top - margins.bottom - (rows-1)*margins.row; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
196 height = height / rows; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
197 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
198 if (strcmp (position_property, "outerposition") ) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
199 ## Calculate the outerposition/position inset |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
200 if (rows > 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
201 inset.top = 8/420; |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
202 inset.bottom = max (polyval ([0.1382,-0.0026], height), 16/420); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
203 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
204 inset.bottom = margins.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
205 inset.top = margins.top; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
206 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
207 if (columns > 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
208 if (strcmpi (units, "normalized")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
209 inset.right = max (polyval ([0.1200,-0.0014], width), 5/560); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
210 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
211 inset.right = max (polyval ([0.1252,-0.0023], width), 5/560); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
212 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
213 inset.left = 22/560; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
214 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
215 inset.left = margins.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
216 inset.right = margins.right; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
217 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
218 ## Apply the inset to the geometries for the "position" property. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
219 margins.column = margins.column - inset.right - inset.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
220 margins.row = margins.row - inset.top - inset.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
221 width = width + inset.right + inset.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
222 height = height + inset.top + inset.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
223 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
224 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
225 yp = fix ((index(:)-1)/columns); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
226 xp = index(:) - yp*columns - 1; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
227 yp = (rows - 1) - yp; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
228 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
229 x0 = xp .* (width + margins.column) + margins.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
230 y0 = yp .* (height + margins.row) + margins.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
231 |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
232 if (strcmp (position_property, "outerposition") ) |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
233 x0 = x0 - inset.left; |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
234 y0 = y0 - inset.bottom; |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
235 endif |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
236 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
237 if (numel(x0) > 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
238 x1 = max (x0) + width; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
239 y1 = max (y0) + height; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
240 x0 = min (x0); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
241 y0 = min (y0); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
242 pos = [x0, y0, x1-x0, y1-y0]; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
243 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
244 pos = [x0, y0, width, height]; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
245 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
246 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
247 endfunction |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
248 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
249 %!demo |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
250 %! clf |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
251 %! r = 3; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
252 %! c = 3; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
253 %! fmt = {'horizontalalignment', 'center', 'verticalalignment', 'middle'}; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
254 %! for n = 1:(r*c) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
255 %! subplot (r, c, n) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
256 %! xlabel (sprintf ("xlabel #%d", n)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
257 %! ylabel (sprintf ("ylabel #%d", n)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
258 %! title (sprintf ("title #%d", n)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
259 %! text (0.5, 0.5, sprintf('subplot(%d,%d,%d)', r, c, n), fmt{:}) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
260 %! axis ([0 1 0 1]) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
261 %! endfor |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
262 %! subplot (r, c, 1:3) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
263 %! xlabel (sprintf ("xlabel #%d:%d", 1, 3)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
264 %! ylabel (sprintf ("ylabel #%d:%d", 1, 3)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
265 %! title (sprintf ("title #%d:%d", 1, 3)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
266 %! text (0.5, 0.5, sprintf('subplot(%d,%d,%d:%d)', r, c, 1, 3), fmt{:}) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
267 %! axis ([0 1 0 1]) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
268 |