comparison scripts/plot/subplot.m @ 12470:64ae43e0e1c0

subplot.m: Use new looseinset property introduced by changeset 12467.
author Ben Abbott <bpabbott@mac.com>
date Tue, 22 Feb 2011 19:46:57 -0500
parents 7b67bbf9dbbb
children 070214996fba
comparison
equal deleted inserted replaced
12469:0ee8d7d60c82 12470:64ae43e0e1c0
108 108
109 if (cols < 1 || rows < 1 || index < 1) 109 if (cols < 1 || rows < 1 || index < 1)
110 error ("subplot: COLS,ROWS,INDEX must be be positive"); 110 error ("subplot: COLS,ROWS,INDEX must be be positive");
111 endif 111 endif
112 112
113 units = get (0, "defaultaxesunits"); 113 axesunits = get (0, "defaultaxesunits");
114 cf = gcf (); 114 cf = gcf ();
115 figunits = get (cf, "units"); 115 figureunits = get (cf, "units");
116 unwind_protect 116 unwind_protect
117 set (0, "defaultaxesunits", "normalized"); 117 units = "normalized";
118 set (0, "defaultaxesunits", units);
118 set (cf, "units", "pixels"); 119 set (cf, "units", "pixels");
119 pos = subplot_position (rows, cols, index, "position", units); 120 pos = subplot_position (rows, cols, index, "position");
120 121
121 set (cf, "nextplot", "add"); 122 set (cf, "nextplot", "add");
122 123
123 found = false; 124 found = false;
124 kids = get (cf, "children"); 125 kids = get (cf, "children");
160 endif 161 endif
161 endfor 162 endfor
162 163
163 if (found) 164 if (found)
164 set (cf, "currentaxes", tmp); 165 set (cf, "currentaxes", tmp);
166 position = get (tmp, "position");
167 outerposition = get (tmp, "outerposition");
165 else 168 else
166 outerposition = subplot_position (rows, cols, index, 169 outerposition = subplot_position (rows, cols, index, "outerposition");
167 "outerposition", units); 170 position = subplot_position (rows, cols, index, "position");
168 position = subplot_position (rows, cols, index, "position", units); 171 tmp = axes ("looseinset", [0 0 0 0], "box", "off",
169 tmp = axes ("position", position, "outerposition", outerposition, 172 "outerposition", outerposition,
170 "activepositionproperty", "outerposition", 173 "position", position);
171 "box", "off");
172 endif 174 endif
173 175
174 if (align_axes && strcmp (get (cf, "__graphics_toolkit__"), "gnuplot")) 176 if (align_axes && strcmp (get (cf, "__graphics_toolkit__"), "gnuplot"))
175 set (tmp, "activepositionproperty", "position"); 177 set (tmp, "activepositionproperty", "position");
176 endif 178 endif
177 179
178 unwind_protect_cleanup 180 unwind_protect_cleanup
179 set (0, "defaultaxesunits", units); 181 set (0, "defaultaxesunits", axesunits);
180 set (cf, "units", figunits); 182 set (cf, "units", figureunits);
181 end_unwind_protect 183 end_unwind_protect
182 184
183 if (nargout > 0) 185 if (nargout > 0)
184 h = tmp; 186 h = tmp;
185 endif 187 endif
186 188
187 endfunction 189 endfunction
188 190
189 function pos = subplot_position (rows, cols, index, position_property, units) 191 function pos = subplot_position (rows, cols, index, position_property)
190 192
191 defaultaxesposition = get (0, "defaultaxesposition"); 193 defaultaxesposition = get (0, "defaultaxesposition");
192 defaultaxesouterposition = get (0, "defaultaxesouterposition"); 194 defaultaxesouterposition = get (0, "defaultaxesouterposition");
193 195
194 if (rows == 1 && cols == 1) 196 if (rows == 1 && cols == 1)
225 ## Calculate the inset of the position relative to the outerposition 227 ## Calculate the inset of the position relative to the outerposition
226 ## The outerpositions are assumed to be tiled. Matlab's implementation 228 ## The outerpositions are assumed to be tiled. Matlab's implementation
227 ## has outerposition overlap. 229 ## has outerposition overlap.
228 if (rows > 1) 230 if (rows > 1)
229 ## Title on top and xlabel & xticks on bottom 231 ## Title on top and xlabel & xticks on bottom
230 inset.top = margins.row / 3; 232 inset.top = margins.row * (1/3);
231 inset.bottom = margins.row * (2/3); 233 inset.bottom = margins.row * (2/3);
232 ## Matlab behavior is approximately ... 234 ## Matlab behavior is approximately ...
233 % inset.bottom = margins.row; 235 % inset.bottom = margins.row;
234 else 236 else
235 inset.bottom = margins.bottom; 237 inset.bottom = margins.bottom;
236 inset.top = margins.top; 238 inset.top = margins.top;
237 endif 239 endif
238 if (cols > 1) 240 if (cols > 1)
239 ## ylabel & yticks on left and some overhang for xticks on right 241 ## ylabel & yticks on left and some overhang for xticks on right
240 inset.right = 0.1 * margins.column; 242 x = 0.1;
241 inset.left = 0.9 * margins.column; 243 inset.right = x * margins.column;
244 inset.left = (1 - x) * margins.column;
242 else 245 else
243 inset.left = margins.left; 246 inset.left = margins.left;
244 inset.right = margins.right; 247 inset.right = margins.right;
245 endif 248 endif
246 ## Apply the inset to the geometries for the "position" property. 249 ## Apply the inset to the geometries for the "position" property.
309 %! ylabel (sprintf ("ylabel (2,2,%d)", n)) 312 %! ylabel (sprintf ("ylabel (2,2,%d)", n))
310 %! title (sprintf ("title (2,2,%d)", n)) 313 %! title (sprintf ("title (2,2,%d)", n))
311 %! endfor 314 %! endfor
312 %! subplot (1, 2, 1, "align") 315 %! subplot (1, 2, 1, "align")
313 %! plot (x, x) 316 %! plot (x, x)
314 %! xlabel (sprintf ("xlabel (1,2,%d)", n)) 317 %! xlabel ("xlabel (1,2,1)")
315 %! ylabel (sprintf ("ylabel (1,2,%d)", n)) 318 %! ylabel ("ylabel (1,2,1)")
316 %! title (sprintf ("title (1,2,%d)", n)) 319 %! title ("title (1,2,1)")
317 320