Mercurial > hg > octave-lyh
annotate scripts/plot/subplot.m @ 11305:c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Thu, 02 Dec 2010 18:46:10 -0500 |
parents | fe3c3dfc07eb |
children | c776f063fefe |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2005, |
8920 | 2 ## 2006, 2007, 2008, 2009 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 -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
21 ## @deftypefn {Function File} {} subplot (@var{rows}, @var{cols}, @var{index}) |
3368 | 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 ## @tex |
36 ## \vskip 10pt | |
37 ## \hfil\vbox{\offinterlineskip\hrule | |
38 ## \halign{\vrule#&&\qquad\hfil#\hfil\qquad\vrule\cr | |
7107 | 39 ## height13pt&1&2&3\cr height12pt&&&\cr\noalign{\hrule} |
40 ## height13pt&4&5&6\cr height12pt&&&\cr\noalign{\hrule}}} | |
3368 | 41 ## \hfil |
42 ## \vskip 10pt | |
43 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8350
diff
changeset
|
44 ## @ifnottex |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
45 ## |
8350
0e3a92a8683c
fix texi bug in subplot.m
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8232
diff
changeset
|
46 ## @example |
3368 | 47 ## @group |
7040 | 48 ## +-----+-----+-----+ |
49 ## | 1 | 2 | 3 | | |
50 ## +-----+-----+-----+ | |
51 ## | 4 | 5 | 6 | | |
52 ## +-----+-----+-----+ | |
8350
0e3a92a8683c
fix texi bug in subplot.m
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8232
diff
changeset
|
53 ## @end group |
6257 | 54 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
55 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8350
diff
changeset
|
56 ## @end ifnottex |
5798 | 57 ## @seealso{plot} |
3368 | 58 ## @end deftypefn |
1540 | 59 |
2312 | 60 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU> |
61 ## Adapted-By: jwe | |
1540 | 62 |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
63 function h = subplot (rows, columns, index, varargin) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
64 |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
65 align_axes = false; |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
66 replace_axes = false; |
6163 | 67 |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
68 if (! (nargin >= 3) && nargin != 1) |
6046 | 69 print_usage (); |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
70 elseif (nargin > 3) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
71 for n = 1:numel(varargin) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
72 switch lower(varargin{n}) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
73 case "align" |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
74 align_axes = true; |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
75 case "replace" |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
76 replace_axes = true; |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
77 otherwise |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
78 print_usage (); |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
79 endswitch |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
80 endfor |
1540 | 81 endif |
82 | |
83 if (nargin == 1) | |
84 | |
4030 | 85 if (! (isscalar (rows) && rows >= 0)) |
1541 | 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 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
96 elseif (! (isscalar (columns) && isscalar (rows))) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
97 error ("subplot: columns, and rows must be scalars"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
98 elseif (any (index < 1) || any (index > rows*columns)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
99 error ("subplot: index value must be greater than 1 and less than rows*columns") |
1540 | 100 endif |
101 | |
102 columns = round (columns); | |
103 rows = round (rows); | |
104 index = round (index); | |
105 | |
106 if (index > columns*rows) | |
107 error ("subplot: index must be less than columns*rows"); | |
108 endif | |
109 | |
110 if (columns < 1 || rows < 1 || index < 1) | |
111 error ("subplot: columns,rows,index must be be positive"); | |
112 endif | |
113 | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
114 units = get (0, "defaultaxesunits"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
115 unwind_protect |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
116 set (0, "defaultaxesunits", "normalized") |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
117 pos = subplot_position (rows, columns, index, "position", units); |
1540 | 118 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
119 cf = gcf (); |
6425 | 120 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
121 set (cf, "nextplot", "add"); |
1540 | 122 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
123 found = false; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
124 kids = get (cf, "children"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
125 for child = reshape (kids, 1, numel (kids)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
126 ## 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
|
127 ## 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
|
128 ## "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
|
129 ## with their corresponding axes). |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
130 if (! ishandle (child)) |
7086 | 131 continue; |
132 endif | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
133 if (strcmp (get (child, "type"), "axes")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
134 ## Skip legend and colorbar objects. |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10931
diff
changeset
|
135 if (strcmp (get (child, "tag"), "legend") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10931
diff
changeset
|
136 || strcmp (get (child, "tag"), "colorbar")) |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
137 continue; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
138 endif |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
139 objpos = get (child, "position"); |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
140 if (all (objpos == pos) && ! replace_axes) |
10549 | 141 ## If the new axes are in exactly the same position as an |
142 ## existing axes object, use the existing axes. | |
143 found = true; | |
144 tmp = child; | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
145 else |
10549 | 146 ## If the new axes overlap an old axes object, delete the old |
147 ## axes. | |
148 x0 = pos(1); | |
149 x1 = x0 + pos(3); | |
150 y0 = pos(2); | |
151 y1 = y0 + pos(4); | |
152 objx0 = objpos(1); | |
153 objx1 = objx0 + objpos(3); | |
154 objy0 = objpos(2); | |
155 objy1 = objy0 + objpos(4); | |
156 if (! (x0 >= objx1 || x1 <= objx0 || y0 >= objy1 || y1 <= objy0)) | |
157 delete (child); | |
158 endif | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
159 endif |
6178 | 160 endif |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
161 endfor |
1540 | 162 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
163 if (found) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
164 set (cf, "currentaxes", tmp); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
165 else |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
166 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
|
167 pos2 = subplot_position (rows, columns, index, "position", units); |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
168 tmp = axes ("outerposition", pos, "position", pos2, |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
169 "activepositionproperty", "outerposition"); |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
170 endif |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
171 |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
172 if (align_axes && strcmp (get (cf, "__backend__"), "gnuplot")) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
173 set (tmp, "activepositionproperty", "position"); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
174 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
175 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
176 unwind_protect_cleanup |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
177 set (0, "defaultaxesunits", units); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
178 end_unwind_protect |
1540 | 179 |
6257 | 180 if (nargout > 0) |
181 h = tmp; | |
1540 | 182 endif |
183 | |
184 endfunction | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
185 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
186 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
|
187 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
188 ## 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
|
189 if (rows == 1 && columns == 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
190 if (strcmpi (position_property, "position")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
191 pos = get (0, "defaultaxesposition"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
192 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
193 pos = get (0, "defaultaxesouterposition"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
194 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
195 return |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
196 endif |
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 ## This produces compatible behavior for the "position" property. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
199 margins.left = 0.130; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
200 margins.right = 0.095; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
201 margins.top = 0.075; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
202 margins.bottom = 0.110; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
203 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
|
204 margins.column = 1 ./ polyval (pc , columns); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
205 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
|
206 margins.row = 1 ./ polyval (pr , rows); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
207 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
208 ## Calculate the width/height of the subplot axes. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
209 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
|
210 width = width / columns; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
211 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
|
212 height = height / rows; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
213 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
214 if (strcmp (position_property, "outerposition") ) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
215 ## Calculate the outerposition/position inset |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
216 if (rows > 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
217 inset.top = 8/420; |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
218 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
|
219 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
220 inset.bottom = margins.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
221 inset.top = margins.top; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
222 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
223 if (columns > 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
224 if (strcmpi (units, "normalized")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
225 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
|
226 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
227 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
|
228 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
229 inset.left = 22/560; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
230 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
231 inset.left = margins.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
232 inset.right = margins.right; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
233 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
234 ## 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
|
235 margins.column = margins.column - inset.right - inset.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
236 margins.row = margins.row - inset.top - inset.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
237 width = width + inset.right + inset.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
238 height = height + inset.top + inset.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
239 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
240 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
241 yp = fix ((index(:)-1)/columns); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
242 xp = index(:) - yp*columns - 1; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
243 yp = (rows - 1) - yp; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
244 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
245 x0 = xp .* (width + margins.column) + margins.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
246 y0 = yp .* (height + margins.row) + margins.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
247 |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
248 if (strcmp (position_property, "outerposition") ) |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
249 x0 = x0 - inset.left; |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
250 y0 = y0 - inset.bottom; |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
251 endif |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
252 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
253 if (numel(x0) > 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
254 x1 = max (x0) + width; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
255 y1 = max (y0) + height; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
256 x0 = min (x0); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
257 y0 = min (y0); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
258 pos = [x0, y0, x1-x0, y1-y0]; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
259 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
260 pos = [x0, y0, width, height]; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
261 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
262 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
263 endfunction |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
264 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
265 %!demo |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
266 %! clf |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
267 %! r = 3; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
268 %! c = 3; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
269 %! fmt = {'horizontalalignment', 'center', 'verticalalignment', 'middle'}; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
270 %! for n = 1:(r*c) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
271 %! subplot (r, c, n) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
272 %! xlabel (sprintf ("xlabel #%d", n)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
273 %! ylabel (sprintf ("ylabel #%d", n)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
274 %! title (sprintf ("title #%d", n)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
275 %! 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
|
276 %! axis ([0 1 0 1]) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
277 %! endfor |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
278 %! subplot (r, c, 1:3) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
279 %! xlabel (sprintf ("xlabel #%d:%d", 1, 3)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
280 %! ylabel (sprintf ("ylabel #%d:%d", 1, 3)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
281 %! title (sprintf ("title #%d:%d", 1, 3)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
282 %! 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
|
283 %! axis ([0 1 0 1]) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
284 |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
285 %!demo |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
286 %! clf |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
287 %! x = 0:1; |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
288 %! for n = 1:4 |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
289 %! subplot (2, 2, n, "align") |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
290 %! plot (x, x) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
291 %! xlabel (sprintf ("xlabel (2,2,%d)", n)) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
292 %! ylabel (sprintf ("ylabel (2,2,%d)", n)) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
293 %! title (sprintf ("title (2,2,%d)", n)) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
294 %! endfor |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
295 %! subplot (1, 2, 1, "align") |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
296 %! plot (x, x) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
297 %! xlabel (sprintf ("xlabel (1,2,%d)", n)) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
298 %! ylabel (sprintf ("ylabel (1,2,%d)", n)) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
299 %! title (sprintf ("title (1,2,%d)", n)) |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
300 |