annotate scripts/plot/subplot.m @ 17085:d3ebc3f9bdbf

doc update for grid and subplot
author Michael Godfrey <michaeldgodfrey@gmail.com>
date Thu, 25 Jul 2013 18:18:32 -0400
parents ddc62f0c7a35
children e38820d1124c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13794
diff changeset
1 ## Copyright (C) 1995-2012 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6828
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6828
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6828
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6828
diff changeset
17 ## <http://www.gnu.org/licenses/>.
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
18
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
20 ## @deftypefn {Function File} {} subplot (@var{rows}, @var{cols}, @var{index})
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
21 ## @deftypefnx {Function File} {} subplot (@var{rcn})
17085
d3ebc3f9bdbf doc update for grid and subplot
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 17022
diff changeset
22 ## @deftypefnx {Function File} {@var{ax}} = subplot (@var{rcn}, ...)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11305
diff changeset
23 ## Set up a plot grid with @var{rows} by @var{cols} subwindows and plot
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6425
diff changeset
24 ## in location given by @var{index}.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3368
diff changeset
25 ##
17085
d3ebc3f9bdbf doc update for grid and subplot
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 17022
diff changeset
26 ## If @var{ax} is provided, subplot returns the axis handle for the subplot.
d3ebc3f9bdbf doc update for grid and subplot
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 17022
diff changeset
27 ## This is usuful for modifying the properties of a subplot.
d3ebc3f9bdbf doc update for grid and subplot
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 17022
diff changeset
28 ##
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
29 ## If only one argument is supplied, then it must be a three digit value
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
30 ## specifying the location in digits 1 (rows) and 2 (columns) and the plot
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
31 ## index in digit 3.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3368
diff changeset
32 ##
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
33 ## The plot index runs row-wise. First all the columns in a row are filled
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
34 ## and then the next row is filled.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3368
diff changeset
35 ##
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5775
diff changeset
36 ## For example, a plot with 2 by 3 grid will have plot indices running as
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
37 ## follows:
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
38 ## @tex
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
39 ## \vskip 10pt
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
40 ## \hfil\vbox{\offinterlineskip\hrule
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
41 ## \halign{\vrule#&&\qquad\hfil#\hfil\qquad\vrule\cr
7107
22397f0fb0b2 [project @ 2007-11-06 20:31:33 by dbateman]
dbateman
parents: 7086
diff changeset
42 ## height13pt&1&2&3\cr height12pt&&&\cr\noalign{\hrule}
22397f0fb0b2 [project @ 2007-11-06 20:31:33 by dbateman]
dbateman
parents: 7086
diff changeset
43 ## height13pt&4&5&6\cr height12pt&&&\cr\noalign{\hrule}}}
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
44 ## \hfil
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
45 ## \vskip 10pt
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
46 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8350
diff changeset
47 ## @ifnottex
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
48 ##
8350
0e3a92a8683c fix texi bug in subplot.m
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8232
diff changeset
49 ## @example
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
50 ## @group
7040
1f16da18d85d [project @ 2007-10-19 18:24:19 by jwe]
jwe
parents: 7017
diff changeset
51 ## +-----+-----+-----+
1f16da18d85d [project @ 2007-10-19 18:24:19 by jwe]
jwe
parents: 7017
diff changeset
52 ## | 1 | 2 | 3 |
1f16da18d85d [project @ 2007-10-19 18:24:19 by jwe]
jwe
parents: 7017
diff changeset
53 ## +-----+-----+-----+
1f16da18d85d [project @ 2007-10-19 18:24:19 by jwe]
jwe
parents: 7017
diff changeset
54 ## | 4 | 5 | 6 |
1f16da18d85d [project @ 2007-10-19 18:24:19 by jwe]
jwe
parents: 7017
diff changeset
55 ## +-----+-----+-----+
8350
0e3a92a8683c fix texi bug in subplot.m
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8232
diff changeset
56 ## @end group
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6178
diff changeset
57 ## @end example
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
58 ##
12575
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 12494
diff changeset
59 ## @var{index} may be a vector. In which case, the new axis will enclose
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 12494
diff changeset
60 ## the grid locations specified. The first demo illustrates an example:
12476
070214996fba subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents: 12470
diff changeset
61 ##
070214996fba subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents: 12470
diff changeset
62 ## @example
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
63 ## demo ("subplot", 1)
12476
070214996fba subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents: 12470
diff changeset
64 ## @end example
070214996fba subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents: 12470
diff changeset
65 ##
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8350
diff changeset
66 ## @end ifnottex
12476
070214996fba subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents: 12470
diff changeset
67 ## @seealso{axes, plot}
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3233
diff changeset
68 ## @end deftypefn
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
69
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
70 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
71 ## Adapted-By: jwe
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
72
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
73 function h = subplot (varargin)
11305
c9df571efe95 subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents: 11149
diff changeset
74
c9df571efe95 subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents: 11149
diff changeset
75 align_axes = false;
c9df571efe95 subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents: 11149
diff changeset
76 replace_axes = false;
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
77 have_position = false;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
78 initial_args_decoded = false;
6163
8614649c454c [project @ 2006-11-14 18:52:34 by jwe]
jwe
parents: 6046
diff changeset
79
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
80 if (nargin > 2)
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
81 ## R, C, N?
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
82 arg1 = varargin{1};
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
83 arg2 = varargin{2};
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
84 arg3 = varargin{3};
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
85 if (isnumeric (arg1) && isscalar (arg1) && isnumeric (arg2)
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
86 && isscalar (arg2) && isnumeric (arg3))
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
87 rows = arg1;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
88 cols = arg2;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
89 index = arg3;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
90 varargin(1:3)= [];
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
91 initial_args_decoded = true;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
92 endif
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
93 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
94
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
95 if (! initial_args_decoded && nargin > 1)
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
96 ## check for 'position', pos, ...
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
97 if (strcmpi (varargin{1}, "position"))
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
98 arg = varargin{2};
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
99 if (isnumeric (arg) && numel (arg) == 4)
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
100 pos = arg;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
101 varargin(1:2) = [];
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
102 have_position = true;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
103 initial_args_decoded = true;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
104 else
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
105 error ("expecting position to be a 4-element numeric array");
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
106 endif
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
107 endif
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
108 endif
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
109
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
110 if (! initial_args_decoded && nargin > 0)
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
111 arg = varargin{1};
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
112 if (nargin == 1 && ishandle (arg))
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
113 ## Axes handle?
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
114 axes (arg);
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
115 cf = get (0, "currentfigure");
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
116 set (cf, "nextplot", "add");
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
117 return;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
118 elseif (isscalar (arg) && arg >= 0)
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
119 ## RCN?
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
120 index = rem (arg, 10);
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
121 arg = (arg - index) / 10;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
122 cols = rem (arg, 10);
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
123 arg = (arg - cols) / 10;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
124 rows = rem (arg, 10);
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
125 varargin(1) = [];
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
126 initial_args_decoded = true;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
127 else
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
128 error ("subplot: expecting axes handle or RCN argument");
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
129 endif
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
130 endif
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
131
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
132 if (! initial_args_decoded)
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
133 print_usage ();
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
134 endif
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
135
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
136 if (! have_position)
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
137 cols = round (cols);
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
138 rows = round (rows);
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
139 index = round (index);
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
140
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
141 if (any (index < 1) || any (index > rows*cols))
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
142 error ("subplot: INDEX value must be greater than 1 and less than ROWS*COLS");
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
143 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
144
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
145 if (cols < 1 || rows < 1 || index < 1)
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
146 error ("subplot: COLS, ROWS, and INDEX must be be positive");
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
147 endif
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
148 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
149
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
150 nargs = numel (varargin);
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
151 while (nargs > 0)
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
152 arg = varargin{1};
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
153 if (strcmpi (arg, "align"))
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
154 align_axes = true;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
155 elseif (strcmpi (arg, "replace"))
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
156 replace_axes = true;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
157 else
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
158 break;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
159 endif
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
160 varargin(1) = [];
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
161 nargs--;
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
162 endwhile
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
163
12470
64ae43e0e1c0 subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents: 12455
diff changeset
164 axesunits = get (0, "defaultaxesunits");
12455
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
165 cf = gcf ();
12470
64ae43e0e1c0 subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents: 12455
diff changeset
166 figureunits = get (cf, "units");
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
167 unwind_protect
12470
64ae43e0e1c0 subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents: 12455
diff changeset
168 units = "normalized";
64ae43e0e1c0 subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents: 12455
diff changeset
169 set (0, "defaultaxesunits", units);
12455
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
170 set (cf, "units", "pixels");
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
171
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
172 ## FIXME: At the moment we force gnuplot to use the aligned mode
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
173 ## which will set "activepositionproperty" to "position".
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
174 ## Τhis can yield to text overlap between labels and titles
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
175 ## see bug #31610
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
176 if (strcmp (get (cf, "__graphics_toolkit__"), "gnuplot"))
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
177 align_axes = true;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
178 endif
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
179
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
180 if (! have_position)
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
181 pos = subplot_position (rows, cols, index, "position");
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
182 outerpos = subplot_position (rows, cols, index, "outerposition");
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
183 box = [pos(1:2), pos(1:2)+pos(3:4)];
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
184 outerbox = [outerpos(1:2), outerpos(1:2)+outerpos(3:4)];
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
185 looseinset = [box(1:2)-outerbox(1:2), outerbox(3:4)-box(3:4)];
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
186 if (align_axes)
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
187 activepositionproperty = "position";
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
188 else
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
189 activepositionproperty = "outerposition";
13794
5b395217ccb9 improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents: 12685
diff changeset
190 endif
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
191 endif
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
192
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
193 set (cf, "nextplot", "add");
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
194
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
195 found = false;
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
196 kids = get (cf, "children");
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
197 for child = reshape (kids, 1, numel (kids))
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
198 ## 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
199 ## 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
200 ## "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
201 ## with their corresponding axes).
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
202 if (! ishandle (child))
7086
625891845df5 [project @ 2007-10-31 17:11:49 by jwe]
jwe
parents: 7040
diff changeset
203 continue;
625891845df5 [project @ 2007-10-31 17:11:49 by jwe]
jwe
parents: 7040
diff changeset
204 endif
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
205 if (strcmp (get (child, "type"), "axes"))
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
206 ## 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
207 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
208 || strcmp (get (child, "tag"), "colorbar"))
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
209 continue;
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
210 endif
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
211 if (align_axes)
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
212 objpos = get (child, "position");
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
213 else
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
214 objpos = get (child, "outerposition");
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
215 endif
15498
623cce4577b3 Fix legend and subplot interaction (bug #37499)
Rik <rik@octave.org>
parents: 14327
diff changeset
216 if (all (abs (objpos - pos) < eps) && ! replace_axes)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
217 ## If the new axes are in exactly the same position as an
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
218 ## existing axes object, use the existing axes.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
219 found = true;
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
220 hsubplot = child;
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
221 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
222 ## If the new axes overlap an old axes object, delete the old
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
223 ## axes.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
224 x0 = pos(1);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
225 x1 = x0 + pos(3);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
226 y0 = pos(2);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11576
diff changeset
227 y1 = y0 + pos(4);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
228 objx0 = objpos(1);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
229 objx1 = objx0 + objpos(3);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
230 objy0 = objpos(2);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
231 objy1 = objy0 + objpos(4);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
232 if (! (x0 >= objx1 || x1 <= objx0 || y0 >= objy1 || y1 <= objy0))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
233 delete (child);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9211
diff changeset
234 endif
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
235 endif
6178
830235f4984f [project @ 2006-11-17 00:16:57 by jwe]
jwe
parents: 6163
diff changeset
236 endif
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
237 endfor
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
238
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
239 if (found)
17022
ddc62f0c7a35 Fix mistake from changeset 942d892524b3.
Stefan Mahr <dac922@gmx.de>
parents: 17012
diff changeset
240 set (cf, "currentaxes", hsubplot);
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
241 else
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
242 hsubplot = axes ("box", "off",
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
243 "position", pos,
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
244 "looseinset", looseinset,
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
245 "activepositionproperty", activepositionproperty,
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
246 varargin{:});
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
247 addproperty ("subplot_align", hsubplot, "boolean", true);
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
248 addlistener (hsubplot, "position", @subplot_align);
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
249 if (! align_axes)
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
250 set (hsubplot, "subplot_align", false)
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
251 subplot_align (hsubplot)
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
252 endif
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
253 endif
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
254
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
255 unwind_protect_cleanup
12470
64ae43e0e1c0 subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents: 12455
diff changeset
256 set (0, "defaultaxesunits", axesunits);
64ae43e0e1c0 subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents: 12455
diff changeset
257 set (cf, "units", figureunits);
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
258 end_unwind_protect
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
259
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6178
diff changeset
260 if (nargout > 0)
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
261 h = hsubplot;
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
262 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
263
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
264 endfunction
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
265
12470
64ae43e0e1c0 subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents: 12455
diff changeset
266 function pos = subplot_position (rows, cols, index, position_property)
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
267
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11305
diff changeset
268 if (rows == 1 && cols == 1)
12455
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
269 ## Trivial result for subplot (1,1,1)
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
270 if (strcmpi (position_property, "position"))
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
271 pos = get (0, "defaultaxesposition");
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
272 else
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
273 pos = get (0, "defaultaxesouterposition");
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
274 endif
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
275 return
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
276 endif
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
277
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
278 if (strcmp (position_property, "outerposition")
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
279 || strcmp (position_property, "outerpositiontight"))
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
280 margins.left = 0.05;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
281 margins.bottom = 0.05;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
282 margins.right = 0.05;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
283 margins.top = 0.05;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
284 if (strcmp (position_property, "outerpositiontight"))
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
285 margins.column = 0.;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
286 margins.row = 0.;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
287 else
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
288 margins.column = 0.04 / cols;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
289 margins.row = 0.04 / rows;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
290 endif
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
291 width = 1 - margins.left - margins.right - (cols-1)*margins.column;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
292 width = width / cols;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
293 height = 1 - margins.top - margins.bottom - (rows-1)*margins.row;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
294 height = height / rows;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
295 else
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
296 defaultaxesposition = get (0, "defaultaxesposition");
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
297
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
298 ## The outer margins surrounding all subplot "positions" are independent
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
299 ## of the number of rows and/or columns
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
300 margins.left = defaultaxesposition(1);
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
301 margins.bottom = defaultaxesposition(2);
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
302 margins.right = 1.0 - margins.left - defaultaxesposition(3);
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
303 margins.top = 1.0 - margins.bottom - defaultaxesposition(4);
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
304
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
305 ## Fit from Matlab experiments
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
306 pc = 1 ./ [0.1860, (margins.left + margins.right - 1)];
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
307 margins.column = 1 ./ polyval (pc , cols);
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
308 pr = 1 ./ [0.2282, (margins.top + margins.bottom - 1)];
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
309 margins.row = 1 ./ polyval (pr , rows);
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
310
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
311 ## Calculate the width/height of the subplot axes "position".
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
312 ## This is also consistent with Matlab
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
313 width = 1 - margins.left - margins.right - (cols-1)*margins.column;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
314 width = width / cols;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
315 height = 1 - margins.top - margins.bottom - (rows-1)*margins.row;
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
316 height = height / rows;
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
317 endif
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
318
12455
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
319 ## Index offsets from the lower left subplot
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
320 yi = fix ((index(:)-1)/cols);
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
321 xi = index(:) - yi*cols - 1;
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
322 yi = (rows - 1) - yi;
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
323
12455
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
324 ## Lower left corner of the subplot, i.e. position(1:2)
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
325 x0 = xi .* (width + margins.column) + margins.left;
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
326 y0 = yi .* (height + margins.row) + margins.bottom;
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
327
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
328 if (numel (x0) > 1)
12455
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
329 ## subplot (row, col, m:n)
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
330 x1 = max (x0(:)) + width;
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
331 y1 = max (y0(:)) + height;
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
332 x0 = min (x0(:));
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
333 y0 = min (y0(:));
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
334 pos = [x0, y0, x1-x0, y1-y0];
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
335 else
12455
7b67bbf9dbbb subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents: 12132
diff changeset
336 ## subplot (row, col, num)
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
337 pos = [x0, y0, width, height];
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
338 endif
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
339
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
340 endfunction
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
341
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
342 function subplot_align (h, varargin)
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
343 persistent updating = false
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
344 if (! updating)
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
345 unwind_protect
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
346 updating = true;
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
347 hfig = ancestor (h, "figure");
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
348 hsubplots = findall (hfig, 'type', 'axes', 'subplot_align', 'off');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
349 if (! isempty (hsubplots))
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
350 tightinset = get (hsubplots, 'tightinset');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
351 if (iscell (tightinset))
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
352 tightinset = max (cell2mat (tightinset));
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
353 endif
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
354 looseinset = get (hsubplots, 'looseinset');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
355 if (iscell (looseinset))
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
356 looseinset = max (cell2mat (looseinset));
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
357 endif
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
358 looseinset = max (tightinset, looseinset);
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
359 set (hsubplots, 'looseinset', looseinset);
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
360 endif
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
361 unwind_protect_cleanup
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
362 updating = false;
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
363 end_unwind_protect
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
364 endif
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
365 endfunction
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14335
diff changeset
366
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
367 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
368 %! clf;
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
369 %! r = 3;
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
370 %! c = 3;
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
371 %! fmt = {'horizontalalignment', 'center', 'verticalalignment', 'middle'};
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
372 %! for n = 1 : r*c
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
373 %! subplot (r, c, n);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
374 %! xlabel (sprintf ('xlabel #%d', n));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
375 %! ylabel (sprintf ('ylabel #%d', n));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
376 %! title (sprintf ('title #%d', n));
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
377 %! text (0.5, 0.5, sprintf ('subplot(%d,%d,%d)', r, c, n), fmt{:});
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
378 %! axis ([0 1 0 1]);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
379 %! end
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
380 %! subplot (r, c, 1:3);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
381 %! xlabel (sprintf ('xlabel #%d:%d', 1, 3));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
382 %! ylabel (sprintf ('ylabel #%d:%d', 1, 3));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
383 %! title (sprintf ('title #%d:%d', 1, 3));
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
384 %! text (0.5, 0.5, sprintf ('subplot(%d,%d,%d:%d)', r, c, 1, 3), fmt{:});
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
385 %! axis ([0 1 0 1]);
8744
4142982c66c6 subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents: 8517
diff changeset
386
11305
c9df571efe95 subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents: 11149
diff changeset
387 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
388 %! clf;
11305
c9df571efe95 subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents: 11149
diff changeset
389 %! x = 0:1;
c9df571efe95 subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents: 11149
diff changeset
390 %! for n = 1:4
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14335
diff changeset
391 %! subplot (2,2,n, 'align');
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
392 %! plot (x, x);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
393 %! xlabel (sprintf ('xlabel (2,2,%d)', n));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
394 %! ylabel (sprintf ('ylabel (2,2,%d)', n));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
395 %! title (sprintf ('title (2,2,%d)', n));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
396 %! end
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14335
diff changeset
397 %! subplot (1,2,1, 'align');
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
398 %! plot (x, x);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
399 %! xlabel ('xlabel (1,2,1)');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
400 %! ylabel ('ylabel (1,2,1)');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
401 %! title ('title (1,2,1)');
11305
c9df571efe95 subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents: 11149
diff changeset
402
16975
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
403 %!demo
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
404 %! clf;
16975
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
405 %! x = 0:10;
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
406 %! ax(1) = subplot (221);
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
407 %! set (ax(1), 'tag', '1');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
408 %! plot (x, rand (3, 11))
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
409 %! title ('x & y labels & ticklabels');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
410 %! xlabel xlabel
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
411 %! ylabel ylabel
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
412 %! ax(2) = subplot (222);
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
413 %! set (ax(2), 'tag', '2');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
414 %! plot (x, rand (3, 11))
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
415 %! title ('no labels');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
416 %! axis ('nolabel','tic')
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
417 %! ax(3) = subplot (223);
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
418 %! set (ax(3), 'tag', '3');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
419 %! plot (x, rand (3, 11))
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
420 %! title ('no labels');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
421 %! axis ('nolabel','tic')
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
422 %! ax(4) = subplot (224);
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
423 %! set (ax(4), 'tag', '4');
16975
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
424 %! plot (x, rand (3, 11))
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
425 %! title ('x & y labels & ticklabels');
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
426 %! xlabel xlabel
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
427 %! ylabel ylabel
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
428
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
429 %!demo
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
430 %! x = 0:10;
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
431 %! subplot (221);
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
432 %! plot (x, rand (3, 11))
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
433 %! ylim ([0, 1]);
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
434 %! text (0.5, 0.5, '{x,y}labels & {x,y}ticklabels', ...
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
435 %! 'horizontalalignment', 'center', ...
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
436 %! 'units', 'normalized');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
437 %! xlabel xlabel
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
438 %! ylabel ylabel
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
439 %! title title
16975
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
440 %! subplot (222);
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
441 %! plot (x, rand (3, 11))
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
442 %! axis ('labely');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
443 %! ylabel ylabel
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
444 %! text (0.5, 0.5, 'no xlabels, xticklabels', ...
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
445 %! 'horizontalalignment', 'center', ...
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
446 %! 'units', 'normalized');
16975
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
447 %! subplot (223);
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
448 %! plot (x, rand (3, 11))
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
449 %! axis ('labelx');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
450 %! text (0.5, 0.5, 'no ylabels, yticklabels', ...
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
451 %! 'horizontalalignment', 'center', ...
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
452 %! 'units', 'normalized');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
453 %! xlabel xlabel
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
454 %! title title
16975
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
455 %! subplot (224);
47cc8e3d9183 Add demo to subplot.
Ben Abbott <bpabbott@mac.com>
parents: 15512
diff changeset
456 %! plot (x, rand (3, 11))
17012
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
457 %! axis ('nolabel','tic');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
458 %! text (0.5, 0.5, 'no {x,y}labels, {x,y}ticklabels', ...
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
459 %! 'horizontalalignment', 'center', ...
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
460 %! 'units', 'normalized');
942d892524b3 Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents: 16975
diff changeset
461