Mercurial > hg > octave-lyh
annotate scripts/plot/subplot.m @ 11198:9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
author | David Bateman <dbateman@free.fr> |
---|---|
date | Sun, 07 Nov 2010 22:35:40 +0100 |
parents | fe3c3dfc07eb |
children | c9df571efe95 |
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 |
6257 | 63 function h = subplot (rows, columns, index) |
6163 | 64 |
1540 | 65 if (nargin != 3 && nargin != 1) |
6046 | 66 print_usage (); |
1540 | 67 endif |
68 | |
69 if (nargin == 1) | |
70 | |
4030 | 71 if (! (isscalar (rows) && rows >= 0)) |
1541 | 72 error ("subplot: input rcn has to be a positive scalar"); |
1540 | 73 endif |
74 | |
1541 | 75 tmp = rows; |
76 index = rem (tmp, 10); | |
77 tmp = (tmp - index) / 10; | |
78 columns = rem (tmp, 10); | |
79 tmp = (tmp - columns) / 10; | |
80 rows = rem (tmp, 10); | |
1540 | 81 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
82 elseif (! (isscalar (columns) && isscalar (rows))) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
83 error ("subplot: columns, and rows must be scalars"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
84 elseif (any (index < 1) || any (index > rows*columns)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
85 error ("subplot: index value must be greater than 1 and less than rows*columns") |
1540 | 86 endif |
87 | |
88 columns = round (columns); | |
89 rows = round (rows); | |
90 index = round (index); | |
91 | |
92 if (index > columns*rows) | |
93 error ("subplot: index must be less than columns*rows"); | |
94 endif | |
95 | |
96 if (columns < 1 || rows < 1 || index < 1) | |
97 error ("subplot: columns,rows,index must be be positive"); | |
98 endif | |
99 | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
100 units = get (0, "defaultaxesunits"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
101 unwind_protect |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
102 set (0, "defaultaxesunits", "normalized") |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
103 pos = subplot_position (rows, columns, index, "position", units); |
1540 | 104 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
105 cf = gcf (); |
6425 | 106 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
107 set (cf, "nextplot", "add"); |
1540 | 108 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
109 found = false; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
110 kids = get (cf, "children"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
111 for child = reshape (kids, 1, numel (kids)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
112 ## 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
|
113 ## 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
|
114 ## "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
|
115 ## with their corresponding axes). |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
116 if (! ishandle (child)) |
7086 | 117 continue; |
118 endif | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
119 if (strcmp (get (child, "type"), "axes")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
120 ## 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
|
121 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
|
122 || strcmp (get (child, "tag"), "colorbar")) |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
123 continue; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
124 endif |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
125 objpos = get (child, "position"); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
126 if (all (objpos == pos)) |
10549 | 127 ## If the new axes are in exactly the same position as an |
128 ## existing axes object, use the existing axes. | |
129 found = true; | |
130 tmp = child; | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
131 else |
10549 | 132 ## If the new axes overlap an old axes object, delete the old |
133 ## axes. | |
134 x0 = pos(1); | |
135 x1 = x0 + pos(3); | |
136 y0 = pos(2); | |
137 y1 = y0 + pos(4); | |
138 objx0 = objpos(1); | |
139 objx1 = objx0 + objpos(3); | |
140 objy0 = objpos(2); | |
141 objy1 = objy0 + objpos(4); | |
142 if (! (x0 >= objx1 || x1 <= objx0 || y0 >= objy1 || y1 <= objy0)) | |
143 delete (child); | |
144 endif | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
145 endif |
6178 | 146 endif |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
147 endfor |
1540 | 148 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
149 if (found) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
150 set (cf, "currentaxes", tmp); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
151 else |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
152 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
|
153 pos2 = subplot_position (rows, columns, index, "position", units); |
10931
a72d53df4fa6
Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents:
10821
diff
changeset
|
154 tmp = axes ("outerposition", pos, |
a72d53df4fa6
Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents:
10821
diff
changeset
|
155 "position", pos2, |
a72d53df4fa6
Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents:
10821
diff
changeset
|
156 "activepositionproperty", "position"); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
157 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
158 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
159 unwind_protect_cleanup |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
160 set (0, "defaultaxesunits", units); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
161 end_unwind_protect |
1540 | 162 |
6257 | 163 if (nargout > 0) |
164 h = tmp; | |
1540 | 165 endif |
166 | |
167 endfunction | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
168 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
169 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
|
170 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
171 ## 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
|
172 if (rows == 1 && columns == 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
173 if (strcmpi (position_property, "position")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
174 pos = get (0, "defaultaxesposition"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
175 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
176 pos = get (0, "defaultaxesouterposition"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
177 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
178 return |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
179 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
180 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
181 ## This produces compatible behavior for the "position" property. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
182 margins.left = 0.130; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
183 margins.right = 0.095; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
184 margins.top = 0.075; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
185 margins.bottom = 0.110; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
186 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
|
187 margins.column = 1 ./ polyval (pc , columns); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
188 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
|
189 margins.row = 1 ./ polyval (pr , rows); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
190 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
191 ## Calculate the width/height of the subplot axes. |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
192 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
|
193 width = width / columns; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
194 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
|
195 height = height / rows; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
196 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
197 if (strcmp (position_property, "outerposition") ) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
198 ## Calculate the outerposition/position inset |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
199 if (rows > 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
200 inset.top = 8/420; |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
201 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
|
202 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
203 inset.bottom = margins.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
204 inset.top = margins.top; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
205 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
206 if (columns > 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
207 if (strcmpi (units, "normalized")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
208 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
|
209 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
210 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
|
211 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
212 inset.left = 22/560; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
213 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
214 inset.left = margins.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
215 inset.right = margins.right; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
216 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
217 ## 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
|
218 margins.column = margins.column - inset.right - inset.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
219 margins.row = margins.row - inset.top - inset.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
220 width = width + inset.right + inset.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
221 height = height + inset.top + inset.bottom; |
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 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
224 yp = fix ((index(:)-1)/columns); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
225 xp = index(:) - yp*columns - 1; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
226 yp = (rows - 1) - yp; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
227 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
228 x0 = xp .* (width + margins.column) + margins.left; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
229 y0 = yp .* (height + margins.row) + margins.bottom; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
230 |
8804
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
231 if (strcmp (position_property, "outerposition") ) |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
232 x0 = x0 - inset.left; |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
233 y0 = y0 - inset.bottom; |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
234 endif |
995f8b064b32
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8744
diff
changeset
|
235 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
236 if (numel(x0) > 1) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
237 x1 = max (x0) + width; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
238 y1 = max (y0) + height; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
239 x0 = min (x0); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
240 y0 = min (y0); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
241 pos = [x0, y0, x1-x0, y1-y0]; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
242 else |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
243 pos = [x0, y0, width, height]; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
244 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
245 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
246 endfunction |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
247 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
248 %!demo |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
249 %! clf |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
250 %! r = 3; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
251 %! c = 3; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
252 %! fmt = {'horizontalalignment', 'center', 'verticalalignment', 'middle'}; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
253 %! for n = 1:(r*c) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
254 %! subplot (r, c, n) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
255 %! xlabel (sprintf ("xlabel #%d", n)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
256 %! ylabel (sprintf ("ylabel #%d", n)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
257 %! title (sprintf ("title #%d", n)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
258 %! 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
|
259 %! axis ([0 1 0 1]) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
260 %! endfor |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
261 %! subplot (r, c, 1:3) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
262 %! xlabel (sprintf ("xlabel #%d:%d", 1, 3)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
263 %! ylabel (sprintf ("ylabel #%d:%d", 1, 3)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
264 %! title (sprintf ("title #%d:%d", 1, 3)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
265 %! 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
|
266 %! axis ([0 1 0 1]) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
267 |