# HG changeset patch # User Ben Abbott # Date 1291333570 18000 # Node ID c9df571efe958c1e32bf2d06705164f29cee5ed6 # Parent c9fefa096ce25f9f05cffcc821de9169b4ab6010 subplot.m: Add suppport for "align" and "replace" options. diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2010-12-02 Ben Abbott + + * plot/subplot.m: Add suppport for "align" and "replace" options. + 2010-11-26 John W. Eaton * pkg/pkg.m: Append directories to EXEC_PATH instead of diff --git a/scripts/plot/subplot.m b/scripts/plot/subplot.m --- a/scripts/plot/subplot.m +++ b/scripts/plot/subplot.m @@ -60,10 +60,24 @@ ## Author: Vinayak Dutt ## Adapted-By: jwe -function h = subplot (rows, columns, index) +function h = subplot (rows, columns, index, varargin) + + align_axes = false; + replace_axes = false; - if (nargin != 3 && nargin != 1) + if (! (nargin >= 3) && nargin != 1) print_usage (); + elseif (nargin > 3) + for n = 1:numel(varargin) + switch lower(varargin{n}) + case "align" + align_axes = true; + case "replace" + replace_axes = true; + otherwise + print_usage (); + endswitch + endfor endif if (nargin == 1) @@ -123,7 +137,7 @@ continue; endif objpos = get (child, "position"); - if (all (objpos == pos)) + if (all (objpos == pos) && ! replace_axes) ## If the new axes are in exactly the same position as an ## existing axes object, use the existing axes. found = true; @@ -151,9 +165,12 @@ else pos = subplot_position (rows, columns, index, "outerposition", units); pos2 = subplot_position (rows, columns, index, "position", units); - tmp = axes ("outerposition", pos, - "position", pos2, - "activepositionproperty", "position"); + tmp = axes ("outerposition", pos, "position", pos2, + "activepositionproperty", "outerposition"); + endif + + if (align_axes && strcmp (get (cf, "__backend__"), "gnuplot")) + set (tmp, "activepositionproperty", "position"); endif unwind_protect_cleanup @@ -265,3 +282,19 @@ %! text (0.5, 0.5, sprintf('subplot(%d,%d,%d:%d)', r, c, 1, 3), fmt{:}) %! axis ([0 1 0 1]) +%!demo +%! clf +%! x = 0:1; +%! for n = 1:4 +%! subplot (2, 2, n, "align") +%! plot (x, x) +%! xlabel (sprintf ("xlabel (2,2,%d)", n)) +%! ylabel (sprintf ("ylabel (2,2,%d)", n)) +%! title (sprintf ("title (2,2,%d)", n)) +%! endfor +%! subplot (1, 2, 1, "align") +%! plot (x, x) +%! xlabel (sprintf ("xlabel (1,2,%d)", n)) +%! ylabel (sprintf ("ylabel (1,2,%d)", n)) +%! title (sprintf ("title (1,2,%d)", n)) +