annotate scripts/plot/draw/pcolor.m @ 17603:dcbab6f3e727

pcolor.m: Use tight axis limits when x-values, y-values are integers. * scripts/plot/draw/pcolor.m: Test x,y values for being integers (such as from meshgrid) and set tight limits if found.
author Rik <rik@octave.org>
date Tue, 08 Oct 2013 08:50:06 -0700
parents 7bb76a22cde1
children 4975ccb0a916
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: 14092
diff changeset
1 ## Copyright (C) 2007-2012 Kai Habel
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
2 ##
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
4 ##
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
8 ## your option) any later version.
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
9 ##
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
14 ##
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
18
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
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
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
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{})
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17121
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
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17211
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: 17211
diff changeset
46 ## the edge visible.
8132
8139ddb83bc3 pcolor.m: Improve doc strings.
Ben Abbott <bpabbott@mac.com>
parents: 7337
diff changeset
47 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17121
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: 17121
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
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
55 ## @end deftypefn
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
56
7110
0e63f1126f01 [project @ 2007-11-06 22:36:22 by jwe]
jwe
parents: 7109
diff changeset
57 ## Author: Kai Habel <kai.habel@gmx.de>
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
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
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
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
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
62
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
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
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents: 7271
diff changeset
67 z = zeros (nr, nc);
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
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
0e63f1126f01 [project @ 2007-11-06 22:36:22 by jwe]
jwe
parents: 7109
diff changeset
72 z = zeros (size (c));
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
73 else
7110
0e63f1126f01 [project @ 2007-11-06 22:36:22 by jwe]
jwe
parents: 7109
diff changeset
74 print_usage ();
0e63f1126f01 [project @ 2007-11-06 22:36:22 by jwe]
jwe
parents: 7109
diff changeset
75 endif
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
76
17211
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17190
diff changeset
77 oldfig = [];
17301
68bcac3c043a Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents: 17281
diff changeset
78 if (! isempty (hax))
17211
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17190
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: 17190
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
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
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 if (! ishold ())
17559
636330292685 pcolor.m: Only turn on axis box when ishold is false.
Rik <rik@octave.org>
parents: 17301
diff changeset
87 set (hax, "view", [0, 90], "box", "on");
17603
dcbab6f3e727 pcolor.m: Use tight axis limits when x-values, y-values are integers.
Rik <rik@octave.org>
parents: 17572
diff changeset
88 ## FIXME: Maybe this should be in the general axis limit setting routine?
dcbab6f3e727 pcolor.m: Use tight axis limits when x-values, y-values are integers.
Rik <rik@octave.org>
parents: 17572
diff changeset
89 ## When values are integers, want to use tight limits.
dcbab6f3e727 pcolor.m: Use tight axis limits when x-values, y-values are integers.
Rik <rik@octave.org>
parents: 17572
diff changeset
90 if (all (x(:) == fix (x(:))))
dcbab6f3e727 pcolor.m: Use tight axis limits when x-values, y-values are integers.
Rik <rik@octave.org>
parents: 17572
diff changeset
91 xlim ([min(x(:)), max(x(:))]);
dcbab6f3e727 pcolor.m: Use tight axis limits when x-values, y-values are integers.
Rik <rik@octave.org>
parents: 17572
diff changeset
92 endif
dcbab6f3e727 pcolor.m: Use tight axis limits when x-values, y-values are integers.
Rik <rik@octave.org>
parents: 17572
diff changeset
93 if (all (y(:) == fix (y(:))))
dcbab6f3e727 pcolor.m: Use tight axis limits when x-values, y-values are integers.
Rik <rik@octave.org>
parents: 17572
diff changeset
94 ylim ([min(y(:)), max(y(:))]);
dcbab6f3e727 pcolor.m: Use tight axis limits when x-values, y-values are integers.
Rik <rik@octave.org>
parents: 17572
diff changeset
95 endif
17076
0de31fe43c4d pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16816
diff changeset
96 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
97
17076
0de31fe43c4d pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16816
diff changeset
98 unwind_protect_cleanup
0de31fe43c4d pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16816
diff changeset
99 if (! isempty (oldfig))
0de31fe43c4d pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16816
diff changeset
100 set (0, "currentfigure", oldfig);
0de31fe43c4d pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16816
diff changeset
101 endif
0de31fe43c4d pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16816
diff changeset
102 end_unwind_protect
7110
0e63f1126f01 [project @ 2007-11-06 22:36:22 by jwe]
jwe
parents: 7109
diff changeset
103
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
104 if (nargout > 0)
17076
0de31fe43c4d pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16816
diff changeset
105 h = htmp;
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
106 endif
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
107
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
108 endfunction
12817
e3e6079039c6 codesprint: 2 demos for pcolor.m dummy for surface.m
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
109
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
110
12817
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');
17121
d4549655b92e Rephrase %!tests to take advantage of single output form of peaks().
Rik <rik@octave.org>
parents: 17076
diff changeset
114 %! 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
115 %! pcolor (Z);
17190
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17126
diff changeset
116 %! 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
117
e3e6079039c6 codesprint: 2 demos for pcolor.m dummy for surface.m
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
118 %!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
119 %! 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
120 %! 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
121 %! [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
122 %! [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
123 %! 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
124 %! shading interp;
17076
0de31fe43c4d pcolor.m: Overhaul to use __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16816
diff changeset
125 %! axis tight;
17190
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17126
diff changeset
126 %! 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
127