Mercurial > hg > octave-lyh
annotate scripts/plot/pcolor.m @ 17455:359366a4994f
waitbar.m: Use Octave coding conventions.
* scripts/plot/waitbar.m: Rename 'retval' to 'h' to match documentation.
Use 'hf', 'hp' for figure and patch graphics handles.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 19 Sep 2013 14:26:47 -0700 |
parents | 68bcac3c043a |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14092
diff
changeset
|
1 ## Copyright (C) 2007-2012 Kai Habel |
7109 | 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:
9245
diff
changeset
|
20 ## @deftypefn {Function File} {} pcolor (@var{x}, @var{y}, @var{c}) |
7109 | 21 ## @deftypefnx {Function File} {} pcolor (@var{c}) |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
22 ## @deftypefnx {Function File} {} pcolor (@var{hax}, @dots{}) |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
23 ## @deftypefnx {Function File} {@var{h} =} pcolor (@dots{}) |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
24 ## Produce a 2-D density plot. |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
25 ## |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
26 ## A @code{pcolor} plot draws rectangles with colors from the matrix @var{c} |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
27 ## over the two-dimensional region represented by the matrices @var{x} and |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
28 ## @var{y}. @var{x} and @var{y} are the coordinates of the mesh's vertices |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
29 ## and are typically the output of @code{meshgrid}. If @var{x} and @var{y} are |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
30 ## vectors, then a typical vertex is (@var{x}(j), @var{y}(i), @var{c}(i,j)). |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
31 ## Thus, columns of @var{c} correspond to different @var{x} values and rows |
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
32 ## of @var{c} correspond to different @var{y} values. |
8132
8139ddb83bc3
pcolor.m: Improve doc strings.
Ben Abbott <bpabbott@mac.com>
parents:
7337
diff
changeset
|
33 ## |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
34 ## The values in @var{c} are scaled to span the range of the current |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
35 ## colormap. Limits may be placed on the color axis by the command |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
36 ## @code{caxis}, or by setting the @code{clim} property of the parent axis. |
8132
8139ddb83bc3
pcolor.m: Improve doc strings.
Ben Abbott <bpabbott@mac.com>
parents:
7337
diff
changeset
|
37 ## |
8139ddb83bc3
pcolor.m: Improve doc strings.
Ben Abbott <bpabbott@mac.com>
parents:
7337
diff
changeset
|
38 ## The face color of each cell of the mesh is determined by interpolating |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
39 ## the values of @var{c} for each of the cell's vertices; Contrast this with |
8132
8139ddb83bc3
pcolor.m: Improve doc strings.
Ben Abbott <bpabbott@mac.com>
parents:
7337
diff
changeset
|
40 ## @code{imagesc} which renders one cell for each element of @var{c}. |
8139ddb83bc3
pcolor.m: Improve doc strings.
Ben Abbott <bpabbott@mac.com>
parents:
7337
diff
changeset
|
41 ## |
8139ddb83bc3
pcolor.m: Improve doc strings.
Ben Abbott <bpabbott@mac.com>
parents:
7337
diff
changeset
|
42 ## @code{shading} modifies an attribute determining the manner by which the |
8139ddb83bc3
pcolor.m: Improve doc strings.
Ben Abbott <bpabbott@mac.com>
parents:
7337
diff
changeset
|
43 ## face color of each cell is interpolated from the values of @var{c}, |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
44 ## and the visibility of the cells' edges. By default the attribute is |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
45 ## @qcode{"faceted"}, which renders a single color for each cell's face with |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
46 ## the edge visible. |
8132
8139ddb83bc3
pcolor.m: Improve doc strings.
Ben Abbott <bpabbott@mac.com>
parents:
7337
diff
changeset
|
47 ## |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
48 ## If the first argument @var{hax} is an axes handle, then plot into this axis, |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
49 ## rather than the current axes returned by @code{gca}. |
8132
8139ddb83bc3
pcolor.m: Improve doc strings.
Ben Abbott <bpabbott@mac.com>
parents:
7337
diff
changeset
|
50 ## |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
51 ## The optional return value @var{h} is a graphics handle to the created |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
52 ## surface object. |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
53 ## |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
54 ## @seealso{caxis, shading, meshgrid, contour, imagesc} |
7109 | 55 ## @end deftypefn |
56 | |
7110 | 57 ## Author: Kai Habel <kai.habel@gmx.de> |
7109 | 58 |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
59 function h = pcolor (varargin) |
7109 | 60 |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
61 [hax, varargin, nargin] = __plt_get_axis_arg__ ("pcolor", varargin{:}); |
7109 | 62 |
63 if (nargin == 1) | |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
64 c = varargin{1}; |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
65 [nr, nc] = size (c); |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
66 [x, y] = meshgrid (1:nc, 1:nr); |
7337 | 67 z = zeros (nr, nc); |
7109 | 68 elseif (nargin == 3) |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
69 x = varargin{1}; |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
70 y = varargin{2}; |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
71 c = varargin{3}; |
7110 | 72 z = zeros (size (c)); |
7109 | 73 else |
7110 | 74 print_usage (); |
75 endif | |
7109 | 76 |
17219
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17198
diff
changeset
|
77 oldfig = []; |
17309
68bcac3c043a
Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents:
17289
diff
changeset
|
78 if (! isempty (hax)) |
17219
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17198
diff
changeset
|
79 oldfig = get (0, "currentfigure"); |
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17198
diff
changeset
|
80 endif |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
81 unwind_protect |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
82 hax = newplot (hax); |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
83 htmp = surface (x, y, z, c); |
7109 | 84 |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
85 set (htmp, "facecolor", "flat"); |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
86 set (hax, "box", "on"); |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
87 if (! ishold ()) |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
88 set (hax, "view", [0, 90]); |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
89 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
90 |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
91 unwind_protect_cleanup |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
92 if (! isempty (oldfig)) |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
93 set (0, "currentfigure", oldfig); |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
94 endif |
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
95 end_unwind_protect |
7110 | 96 |
7109 | 97 if (nargout > 0) |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
98 h = htmp; |
7109 | 99 endif |
100 | |
101 endfunction | |
12817
e3e6079039c6
codesprint: 2 demos for pcolor.m dummy for surface.m
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
102 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
103 |
12817
e3e6079039c6
codesprint: 2 demos for pcolor.m dummy for surface.m
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
104 %!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
|
105 %! clf; |
14247
c4fa5e0b6193
test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
106 %! colormap ('default'); |
17125
d4549655b92e
Rephrase %!tests to take advantage of single output form of peaks().
Rik <rik@octave.org>
parents:
17076
diff
changeset
|
107 %! Z = peaks (); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
108 %! pcolor (Z); |
17198
df4c4b7708a4
Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents:
17130
diff
changeset
|
109 %! title ('pcolor() of peaks with facet shading'); |
12817
e3e6079039c6
codesprint: 2 demos for pcolor.m dummy for surface.m
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
110 |
e3e6079039c6
codesprint: 2 demos for pcolor.m dummy for surface.m
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
111 %!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
|
112 %! clf; |
14247
c4fa5e0b6193
test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
113 %! colormap ('default'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
114 %! [X,Y,Z] = sombrero (); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
115 %! [Fx,Fy] = gradient (Z); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
116 %! pcolor (X,Y,Fx+Fy); |
12817
e3e6079039c6
codesprint: 2 demos for pcolor.m dummy for surface.m
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
117 %! shading interp; |
17076
0de31fe43c4d
pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
118 %! axis tight; |
17198
df4c4b7708a4
Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents:
17130
diff
changeset
|
119 %! title ('pcolor() of peaks with interp shading'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
120 |