Mercurial > hg > octave-nkf
annotate scripts/plot/plotmatrix.m @ 10845:c0ffe159ba1a
version is now 3.3.52+
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 01 Aug 2010 14:50:51 -0400 |
parents | be55736a0783 |
children | fe3c3dfc07eb |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2008, 2009 David Bateman |
8127 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} plotmatrix (@var{x}, @var{y}) |
8127 | 21 ## @deftypefnx {Function File} {} plotmatrix (@var{x}) |
22 ## @deftypefnx {Function File} {} plotmatrix (@dots{}, @var{style}) | |
23 ## @deftypefnx {Function File} {} plotmatrix (@var{h}, @dots{}) | |
24 ## @deftypefnx {Function File} {[@var{h}, @var{ax}, @var{bigax}, @var{p}, @var{pax}] =} plotmatrix (@dots{}) | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8190
diff
changeset
|
25 ## Scatter plot of the columns of one matrix against another. Given the |
8127 | 26 ## arguments @var{x} and @var{y}, that have a matching number of rows, |
27 ## @code{plotmatrix} plots a set of axes corresponding to | |
28 ## | |
29 ## @example | |
30 ## plot (@var{x} (:, i), @var{y} (:, j) | |
31 ## @end example | |
32 ## | |
33 ## Given a single argument @var{x}, then this is equivalent to | |
34 ## | |
35 ## @example | |
36 ## plotmatrix (@var{x}, @var{x}) | |
37 ## @end example | |
38 ## | |
39 ## @noindent | |
40 ## except that the diagonal of the set of axes will be replaced with the | |
41 ## histogram @code{hist (@var{x} (:, i))}. | |
42 ## | |
43 ## The marker to use can be changed with the @var{style} argument, that is a | |
44 ## string defining a marker in the same manner as the @code{plot} | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8190
diff
changeset
|
45 ## command. If a leading axes handle @var{h} is passed to |
8127 | 46 ## @code{plotmatrix}, then this axis will be used for the plot. |
47 ## | |
48 ## The optional return value @var{h} provides handles to the individual | |
49 ## graphics objects in the scatter plots, whereas @var{ax} returns the | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8190
diff
changeset
|
50 ## handles to the scatter plot axis objects. @var{bigax} is a hidden |
8127 | 51 ## axis object that surrounds the other axes, such that the commands |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
52 ## @code{xlabel}, @code{title}, etc., will be associated with this hidden |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8190
diff
changeset
|
53 ## axis. Finally @var{p} returns the graphics objects associated with |
8127 | 54 ## the histogram and @var{pax} the corresponding axes objects. |
55 ## | |
56 ## @example | |
57 ## @group | |
58 ## plotmatrix (randn (100, 3), 'g+') | |
59 ## @end group | |
60 ## @end example | |
61 ## | |
62 ## @end deftypefn | |
63 | |
64 function [h, ax, bigax, p, pax] = plotmatrix (varargin) | |
65 | |
66 [bigax2, varargin, nargin] = __plt_get_axis_arg__ ("plotmatrix", varargin{:}); | |
67 | |
68 if (nargin > 3 || nargin < 1) | |
69 print_usage (); | |
70 else | |
71 oldh = gca (); | |
72 unwind_protect | |
73 axes (bigax2); | |
74 newplot (); | |
75 [h2, ax2, p2, pax2, need_usage] = __plotmatrix__ (bigax2, varargin{:}); | |
76 if (need_usage) | |
10549 | 77 print_usage (); |
8127 | 78 endif |
79 if (nargout > 0) | |
10549 | 80 h = h2; |
81 ax = ax2; | |
82 bigax = bigax2; | |
83 p = p2; | |
84 pax = pax2; | |
8127 | 85 endif |
86 axes (bigax2); | |
87 ctext = text (0, 0, "", "visible", "off", | |
10549 | 88 "handlevisibility", "off", "xliminclude", "off", |
89 "yliminclude", "off", "zliminclude", "off", | |
90 "deletefcn", {@plotmatrixdelete, [ax2; pax2]}); | |
8127 | 91 set (bigax2, "visible", "off"); |
92 unwind_protect_cleanup | |
93 axes (oldh); | |
94 end_unwind_protect | |
95 endif | |
96 endfunction | |
97 | |
98 %!demo | |
99 %! plotmatrix (randn (100, 3), 'g+') | |
100 | |
101 function plotmatrixdelete (h, d, ax) | |
102 for i = 1 : numel (ax) | |
103 hc = ax(i); | |
104 if (ishandle (hc) && strcmp (get (hc, "type"), "axes") && | |
10549 | 105 strcmpi (get (hc, "beingdeleted"), "off")) |
8127 | 106 parent = get (hc, "parent"); |
107 ## If the parent is invalid or being deleted, then do nothing | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
8127
diff
changeset
|
108 if (ishandle (parent) && strcmpi (get (parent, "beingdeleted"), "off")) |
10549 | 109 delete (hc); |
8127 | 110 endif |
111 endif | |
112 endfor | |
113 endfunction | |
114 | |
115 function [h, ax, p, pax, need_usage] = __plotmatrix__ (bigax, varargin) | |
116 need_usage = false; | |
117 have_line_spec = false; | |
118 have_hist = false; | |
119 parent = get (bigax, "parent"); | |
120 for i = 1 : nargin - 1 | |
121 arg = varargin{i}; | |
122 if (ischar (arg) || iscell (arg)) | |
123 [linespec, valid] = __pltopt__ ("plotmatrix", varargin{i}, false); | |
124 if (valid) | |
10549 | 125 have_line_spec = true; |
126 linespec = varargin(i); | |
127 varargin(i) = []; | |
128 nargin = nargin - 1; | |
129 break; | |
8127 | 130 else |
10549 | 131 need_usage = true; |
132 returm; | |
8127 | 133 endif |
134 endif | |
135 endfor | |
136 | |
137 if (nargin == 2) | |
138 X = varargin{1}; | |
139 Y = X; | |
140 have_hist = true; | |
141 elseif (nargin == 3) | |
142 X = varargin{1}; | |
143 Y = varargin{2}; | |
144 else | |
145 need_usage = true; | |
146 returm; | |
147 endif | |
148 | |
149 if (rows(X) != rows(Y)) | |
150 error ("plotmatrix: dimension mismatch in the arguments"); | |
151 endif | |
152 | |
153 [dummy, m] = size (X); | |
154 [dummy, n] = size (Y); | |
155 | |
156 h = []; | |
157 ax = []; | |
158 p = []; | |
159 pax = []; | |
160 | |
161 xsize = 0.9 / m; | |
162 ysize = 0.9 / n; | |
163 xoff = 0.05; | |
164 yoff = 0.05; | |
165 border = [0.130, 0.110, 0.225, 0.185] .* [xsize, ysize, xsize, ysize]; | |
166 border(3:4) = - border(3:4) - border(1:2); | |
167 | |
168 for i = 1 : n | |
169 for j = 1 : m | |
170 pos = [xsize * (j - 1) + xoff, ysize * (n - i) + yoff, xsize, ysize]; | |
171 tmp = axes ("outerposition", pos, "position", pos + border, | |
10549 | 172 "parent", parent); |
8127 | 173 if (i == j && have_hist) |
10549 | 174 pax = [pax ; tmp]; |
175 [nn, xx] = hist (X(:, i)); | |
176 tmp = bar (xx, nn, 1.0); | |
177 p = [p; tmp]; | |
8127 | 178 else |
10549 | 179 ax = [ax ; tmp]; |
180 if (have_line_spec) | |
181 tmp = plot (X (:, i), Y (:, j), linespec); | |
182 else | |
183 tmp = plot (X (:, i), Y (:, j), "."); | |
184 endif | |
185 h = [h ; tmp]; | |
8127 | 186 endif |
187 endfor | |
188 endfor | |
189 endfunction |