Mercurial > hg > octave-nkf
annotate scripts/plot/plotmatrix.m @ 14237:11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Add clf() to all demos using plot features to get reproducibility.
Use 64 as input to all colormaps (jet (64)) to get reproducibility.
* bicubic.m, cell2mat.m, celldisp.m, cplxpair.m, interp1.m, interp2.m,
interpft.m, interpn.m, profile.m, profshow.m, convhull.m, delaunay.m,
griddata.m, inpolygon.m, voronoi.m, autumn.m, bone.m, contrast.m, cool.m,
copper.m, flag.m, gmap40.m, gray.m, hot.m, hsv.m, image.m, imshow.m, jet.m,
ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, white.m, winter.m,
condest.m, onenormest.m, axis.m, clabel.m, colorbar.m, comet.m, comet3.m,
compass.m, contour.m, contour3.m, contourf.m, cylinder.m, daspect.m,
ellipsoid.m, errorbar.m, ezcontour.m, ezcontourf.m, ezmesh.m, ezmeshc.m,
ezplot.m, ezplot3.m, ezpolar.m, ezsurf.m, ezsurfc.m, feather.m, fill.m,
fplot.m, grid.m, hold.m, isosurface.m, legend.m, loglog.m, loglogerr.m,
pareto.m, patch.m, pbaspect.m, pcolor.m, pie.m, pie3.m, plot3.m, plotmatrix.m,
plotyy.m, polar.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m, ribbon.m,
rose.m, scatter.m, scatter3.m, semilogx.m, semilogxerr.m, semilogy.m,
semilogyerr.m, shading.m, slice.m, sombrero.m, stairs.m, stem.m, stem3.m,
subplot.m, surf.m, surfc.m, surfl.m, surfnorm.m, text.m, title.m, trimesh.m,
triplot.m, trisurf.m, uigetdir.m, uigetfile.m, uimenu.m, uiputfile.m,
waitbar.m, xlim.m, ylim.m, zlim.m, mkpp.m, pchip.m, polyaffine.m, spline.m,
bicgstab.m, cgs.m, gplot.m, pcg.m, pcr.m, treeplot.m, strtok.m, demo.m,
example.m, rundemos.m, speed.m, test.m, calendar.m, datestr.m, datetick.m,
weekday.m: Revamp %!demos to use Octave coding conventions on spacing, etc.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 20 Jan 2012 12:59:53 -0800 |
parents | 72c96de7a403 |
children | 4506eade9f04 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14092
diff
changeset
|
1 ## Copyright (C) 2008-2012 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 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
33 ## Given a single argument @var{x}, then this is equivalent to |
8127 | 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 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
43 ## The marker to use can be changed with the @var{style} argument, that is a |
8127 | 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 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
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); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
87 ctext = text (0, 0, "", "visible", "off", |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
88 "handlevisibility", "off", "xliminclude", "off", |
10549 | 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 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
100 %! plotmatrix (randn (100, 3), "g+"); |
8127 | 101 |
102 function plotmatrixdelete (h, d, ax) | |
103 for i = 1 : numel (ax) | |
104 hc = ax(i); | |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10793
diff
changeset
|
105 if (ishandle (hc) && strcmp (get (hc, "type"), "axes") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10793
diff
changeset
|
106 && strcmpi (get (hc, "beingdeleted"), "off")) |
8127 | 107 parent = get (hc, "parent"); |
108 ## 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
|
109 if (ishandle (parent) && strcmpi (get (parent, "beingdeleted"), "off")) |
10549 | 110 delete (hc); |
8127 | 111 endif |
112 endif | |
113 endfor | |
114 endfunction | |
115 | |
116 function [h, ax, p, pax, need_usage] = __plotmatrix__ (bigax, varargin) | |
117 need_usage = false; | |
118 have_line_spec = false; | |
119 have_hist = false; | |
120 parent = get (bigax, "parent"); | |
121 for i = 1 : nargin - 1 | |
122 arg = varargin{i}; | |
123 if (ischar (arg) || iscell (arg)) | |
124 [linespec, valid] = __pltopt__ ("plotmatrix", varargin{i}, false); | |
125 if (valid) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
126 have_line_spec = true; |
10549 | 127 linespec = varargin(i); |
128 varargin(i) = []; | |
129 nargin = nargin - 1; | |
130 break; | |
8127 | 131 else |
10549 | 132 need_usage = true; |
133 returm; | |
8127 | 134 endif |
135 endif | |
136 endfor | |
137 | |
138 if (nargin == 2) | |
139 X = varargin{1}; | |
140 Y = X; | |
141 have_hist = true; | |
142 elseif (nargin == 3) | |
143 X = varargin{1}; | |
144 Y = varargin{2}; | |
145 else | |
146 need_usage = true; | |
147 returm; | |
148 endif | |
149 | |
150 if (rows(X) != rows(Y)) | |
151 error ("plotmatrix: dimension mismatch in the arguments"); | |
152 endif | |
153 | |
154 [dummy, m] = size (X); | |
155 [dummy, n] = size (Y); | |
156 | |
157 h = []; | |
158 ax = []; | |
159 p = []; | |
160 pax = []; | |
161 | |
162 xsize = 0.9 / m; | |
163 ysize = 0.9 / n; | |
164 xoff = 0.05; | |
165 yoff = 0.05; | |
166 border = [0.130, 0.110, 0.225, 0.185] .* [xsize, ysize, xsize, ysize]; | |
167 border(3:4) = - border(3:4) - border(1:2); | |
168 | |
169 for i = 1 : n | |
170 for j = 1 : m | |
171 pos = [xsize * (j - 1) + xoff, ysize * (n - i) + yoff, xsize, ysize]; | |
172 tmp = axes ("outerposition", pos, "position", pos + border, | |
10549 | 173 "parent", parent); |
8127 | 174 if (i == j && have_hist) |
10549 | 175 pax = [pax ; tmp]; |
176 [nn, xx] = hist (X(:, i)); | |
177 tmp = bar (xx, nn, 1.0); | |
178 p = [p; tmp]; | |
8127 | 179 else |
10549 | 180 ax = [ax ; tmp]; |
181 if (have_line_spec) | |
182 tmp = plot (X (:, i), Y (:, j), linespec); | |
183 else | |
184 tmp = plot (X (:, i), Y (:, j), "."); | |
185 endif | |
186 h = [h ; tmp]; | |
8127 | 187 endif |
188 endfor | |
189 endfor | |
190 endfunction |