|
40 | 40 | ## is a single color specification such as a @code{plot} format or an |
41 | 41 | ## RGB-triple. In this case the polygon(s) will have one unique color. If |
42 | 42 | ## @var{c} is a vector or matrix then the color data is first scaled using |
43 | | -## @code{clim} and then indexed into the current colormap. A row vector will |
44 | | -## color each polygon (a column from matrices @var{x} and @var{y}) with a |
45 | | -## single computed color. A matrix @var{c} of the same size as @var{x} and |
46 | | -## @var{y} will compute the color of each vertex and then interpolate the face |
47 | | -## color between the vertices. |
| 43 | +## @code{clim} and then indexed into the current colormap. A vector will color |
| 44 | +## each polygon (a column from matrices @var{x} and @var{y}) with a single |
| 45 | +## computed color. A matrix @var{c} of the same size as @var{x} and @var{y} |
| 46 | +## will compute the color of each vertex and then interpolate the face color |
| 47 | +## between the vertices. |
48 | 48 | ## |
49 | 49 | ## Multiple property/value pairs for the underlying patch object may be |
50 | 50 | ## specified, but they must appear in pairs. The full list of properties is |
|
53 | 53 | ## If the first argument @var{hax} is an axes handle, then plot into this axes, |
54 | 54 | ## rather than the current axes returned by @code{gca}. |
55 | 55 | ## |
56 | | -## The optional return value @var{h} is a vector of graphics handles to |
57 | | -## the created patch objects. |
| 56 | +## The optional return value @var{h} is a vector of graphics handles to the |
| 57 | +## created patch objects. |
58 | 58 | ## |
59 | 59 | ## Example: red square |
60 | 60 | ## |
|
102 | 102 | unwind_protect |
103 | 103 | set (hax, "nextplot", "add"); |
104 | 104 |
|
105 | | - for i = 1 : length (iargs) |
| 105 | + for i = 1 : numel (iargs) |
106 | 106 | x = varargin{iargs(i)}; |
107 | 107 | y = varargin{iargs(i) + 1}; |
108 | 108 | cdata = varargin{iargs(i) + 2}; |
109 | 109 |
|
110 | | - if (! size_equal (x, y)) |
111 | | - if (iscolumn (y) && rows (y) == rows (x)) |
112 | | - y = repmat (y, [1, columns(x)]); |
113 | | - elseif (iscolumn (x) && rows (x) == rows (y)) |
114 | | - x = repmat (x, [1, columns(y)]); |
115 | | - else |
116 | | - error ("fill: X and Y must have same number of rows"); |
117 | | - endif |
118 | | - endif |
| 110 | + ## FIXME: Probably should validate that x, y, cdata are 2-D. |
119 | 111 |
|
120 | 112 | if (isrow (x)) |
121 | 113 | x = x(:); |
|
124 | 116 | y = y(:); |
125 | 117 | endif |
126 | 118 |
|
127 | | - if (ischar (cdata) || isequal (size (cdata), [1, 3])) |
| 119 | + if (! size_equal (x, y)) |
| 120 | + if (iscolumn (x)) |
| 121 | + rx = rows (x); |
| 122 | + [ry, cy] = size (y); |
| 123 | + if (rx == ry) |
| 124 | + x = repmat (x, [1, cy]); |
| 125 | + elseif (rx == cy) |
| 126 | + y = y.'; |
| 127 | + x = repmat (x, [1, ry]); |
| 128 | + else |
| 129 | + error ("fill: vector X and matrix Y must have a length which matches along one dimension"); |
| 130 | + endif |
| 131 | + elseif (iscolumn (y)) |
| 132 | + ry = rows (y); |
| 133 | + [rx, cx] = size (x); |
| 134 | + if (ry == rx) |
| 135 | + y = repmat (y, [1, cx]); |
| 136 | + elseif (ry == cx) |
| 137 | + x = x.'; |
| 138 | + y = repmat (y, [1, rx]); |
| 139 | + else |
| 140 | + error ("fill: matrix X and vector Y must have a length which matches along one dimension"); |
| 141 | + endif |
| 142 | + else |
| 143 | + error ("fill: matrices X and Y must be the same size"); |
| 144 | + endif |
| 145 | + endif |
| 146 | + |
| 147 | + ## Test for color specification as text ('r') or RGB triple. |
| 148 | + if (ischar (cdata) || |
| 149 | + (all (size (cdata) == [1, 3]) && all (cdata >= 0 & cdata <= 1))) |
128 | 150 | one_color = true; |
129 | 151 | else |
130 | 152 | one_color = false; |
131 | 153 | endif |
132 | 154 |
|
133 | | - ## For Matlab compatibility, replicate cdata to match size of data |
134 | | - if (! one_color && iscolumn (cdata)) |
135 | | - sz = size (x); |
136 | | - if (all (sz > 1)) |
137 | | - cdata = repmat (cdata, [1, sz(2)]); |
| 155 | + ## Manage cdata to ensure for loop below works |
| 156 | + if (! one_color && isvector (cdata)) |
| 157 | + if (numel (cdata) == columns (x)) |
| 158 | + ## One color per polygon |
| 159 | + cdata = cdata(:).'; |
| 160 | + elseif (numel (cdata) == rows (x)) |
| 161 | + ## Vertex colors. Replicate cdata to match size of data. |
| 162 | + cdata = repmat (cdata(:), [1, columns(x)]); |
| 163 | + else |
| 164 | + error ("fill: invalid format for color data C"); |
138 | 165 | endif |
139 | 166 | endif |
140 | 167 |
|
|
0 commit comments