Mercurial > hg > octave-lyh
comparison scripts/plot/plot3.m @ 8078:4665276ff7f6
correctly plot matrices in plot3
author | David Bateman <dbateman@free.fr> |
---|---|
date | Tue, 02 Sep 2008 14:50:08 -0400 |
parents | a028a5960e18 |
children | 79c874fe5100 |
comparison
equal
deleted
inserted
replaced
8077:a4e03f9b4b8a | 8078:4665276ff7f6 |
---|---|
159 if (isvector (z)) | 159 if (isvector (z)) |
160 x = x(:); | 160 x = x(:); |
161 y = y(:); | 161 y = y(:); |
162 z = z(:); | 162 z = z(:); |
163 elseif (length (x) == rows (z) && length (y) == columns (z)) | 163 elseif (length (x) == rows (z) && length (y) == columns (z)) |
164 [x, y] = meshgrid (x, y); | |
165 else | |
164 error ("plot3: [length(x), length(y)] must match size(z)"); | 166 error ("plot3: [length(x), length(y)] must match size(z)"); |
165 else | |
166 [x, y] = meshgrid (x, y); | |
167 endif | 167 endif |
168 endif | 168 endif |
169 | 169 |
170 if (! size_equal (x, y, z)) | 170 if (! size_equal (x, y, z)) |
171 error ("plot3: x, y, and z must have the same shape"); | 171 error ("plot3: x, y, and z must have the same shape"); |
173 | 173 |
174 key = options.key; | 174 key = options.key; |
175 if (! isempty (key)) | 175 if (! isempty (key)) |
176 set (gca (), "key", "on"); | 176 set (gca (), "key", "on"); |
177 endif | 177 endif |
178 color = options.color; | 178 |
179 if (isempty (options.color)) | 179 for i = 1 : columns (x) |
180 color = __next_line_color__ (); | 180 color = options.color; |
181 endif | 181 if (isempty (options.color)) |
182 | 182 color = __next_line_color__ (); |
183 hg = hggroup (); | 183 endif |
184 tmp(++idx) = hg; | 184 |
185 properties = __add_datasource__ ("plot3", hg, {"x", "y", "z"}, properties{:}); | 185 hg = hggroup (); |
186 | 186 tmp(++idx) = hg; |
187 hline = line (x(:), y(:), z(:), "keylabel", key, "color", color, | 187 properties = __add_datasource__ ("plot3", hg, {"x", "y", "z"}, properties{:}); |
188 "linestyle", options.linestyle, | 188 |
189 "marker", options.marker, "parent", hg); | 189 hline = line (x(:, i), y(:, i), z(:, i), "keylabel", key, |
190 | 190 "color", color, |
191 __add_line_series__ (hline, hg); | 191 "linestyle", options.linestyle, |
192 | 192 "marker", options.marker, "parent", hg); |
193 set (hg, properties{:}); | 193 |
194 __add_line_series__ (hline, hg); | |
195 | |
196 if (! isempty (properties)) | |
197 set (hg, properties{:}); | |
198 endif | |
199 endfor | |
194 | 200 |
195 x_set = 0; | 201 x_set = 0; |
196 y_set = 0; | 202 y_set = 0; |
197 z_set = 0; | 203 z_set = 0; |
198 fmt_set = 0; | 204 fmt_set = 0; |
211 if (isvector (z)) | 217 if (isvector (z)) |
212 x = x(:); | 218 x = x(:); |
213 y = y(:); | 219 y = y(:); |
214 z = z(:); | 220 z = z(:); |
215 elseif (length (x) == rows (z) && length (y) == columns (z)) | 221 elseif (length (x) == rows (z) && length (y) == columns (z)) |
222 [x, y] = meshgrid (x, y); | |
223 else | |
216 error ("plot3: [length(x), length(y)] must match size(z)"); | 224 error ("plot3: [length(x), length(y)] must match size(z)"); |
217 else | |
218 [x, y] = meshgrid (x, y); | |
219 endif | 225 endif |
220 endif | 226 endif |
221 | 227 |
222 if (! size_equal (x, y, z)) | 228 if (! size_equal (x, y, z)) |
223 error ("plot3: x, y, and z must have the same shape"); | 229 error ("plot3: x, y, and z must have the same shape"); |
226 options = __default_plot_options__ (); | 232 options = __default_plot_options__ (); |
227 key = options.key; | 233 key = options.key; |
228 if (! isempty (key)) | 234 if (! isempty (key)) |
229 set (gca (), "key", "on"); | 235 set (gca (), "key", "on"); |
230 endif | 236 endif |
231 color = options.color; | 237 |
232 if (isempty (color)) | 238 for i = 1 : columns (x) |
233 color = __next_line_color__ (); | 239 color = options.color; |
234 endif | 240 if (isempty (color)) |
235 | 241 color = __next_line_color__ (); |
236 hg = hggroup (); | 242 endif |
237 tmp(++idx) = hg; | 243 |
238 properties = __add_datasource__ ("plot3", hg, {"x", "y", "z"}, properties{:}); | 244 hg = hggroup (); |
239 | 245 tmp(++idx) = hg; |
240 hline = line (x(:), y(:), z(:), "keylabel", key, "color", color, | 246 properties = __add_datasource__ ("plot3", hg, {"x", "y", "z"}, properties{:}); |
241 "linestyle", options.linestyle, | 247 |
242 "marker", options.marker, "parent", hg); | 248 hline = line (x(:, i), y(:, i), z(:, i), "keylabel", key, |
243 | 249 "color", color, |
244 __add_line_series__ (hline, hg); | 250 "linestyle", options.linestyle, |
245 | 251 "marker", options.marker, "parent", hg); |
246 set (hg, properties{:}); | 252 |
253 __add_line_series__ (hline, hg); | |
254 | |
255 if (! isempty (properties)) | |
256 set (hg, properties{:}); | |
257 endif | |
258 endfor | |
247 | 259 |
248 x = new; | 260 x = new; |
249 y_set = 0; | 261 y_set = 0; |
250 z_set = 0; | 262 z_set = 0; |
251 fmt_set = 0; | 263 fmt_set = 0; |
283 if (isvector (z)) | 295 if (isvector (z)) |
284 x = x(:); | 296 x = x(:); |
285 y = y(:); | 297 y = y(:); |
286 z = z(:); | 298 z = z(:); |
287 elseif (length (x) == rows (z) && length (y) == columns (z)) | 299 elseif (length (x) == rows (z) && length (y) == columns (z)) |
300 [x, y] = meshgrid (x, y); | |
301 else | |
288 error ("plot3: [length(x), length(y)] must match size(z)"); | 302 error ("plot3: [length(x), length(y)] must match size(z)"); |
289 else | |
290 [x, y] = meshgrid (x, y); | |
291 endif | 303 endif |
292 endif | 304 endif |
293 | 305 |
294 if (! size_equal (x, y, z)) | 306 if (! size_equal (x, y, z)) |
295 error ("plot3: x, y, and z must have the same shape"); | 307 error ("plot3: x, y, and z must have the same shape"); |
298 options = __default_plot_options__ (); | 310 options = __default_plot_options__ (); |
299 key = options.key; | 311 key = options.key; |
300 if (! isempty (key)) | 312 if (! isempty (key)) |
301 set (gca (), "key", "on"); | 313 set (gca (), "key", "on"); |
302 endif | 314 endif |
303 color = options.color; | 315 |
304 if (isempty (color)) | 316 for i = 1 : columns (x) |
305 color = __next_line_color__ (); | 317 color = options.color; |
306 endif | 318 if (isempty (color)) |
307 | 319 color = __next_line_color__ (); |
308 hg = hggroup (); | 320 endif |
309 tmp(++idx) = hg; | 321 |
310 properties = __add_datasource__ ("plot3", hg, {"x", "y", "z"}, properties{:}); | 322 hg = hggroup (); |
311 | 323 tmp(++idx) = hg; |
312 hline = line (x(:), y(:), z(:), "keylabel", key, "color", color, | 324 properties = __add_datasource__ ("plot3", hg, {"x", "y", "z"}, properties{:}); |
313 "linestyle", options.linestyle, | 325 |
314 "marker", options.marker, "parent", hg); | 326 hline = line (x(:, i), y(:, i), z(:, i), "keylabel", key, |
315 | 327 "color", color, |
316 __add_line_series__ (hline, hg); | 328 "linestyle", options.linestyle, |
317 | 329 "marker", options.marker, "parent", hg); |
330 | |
331 __add_line_series__ (hline, hg); | |
332 | |
333 if (! isempty (properties)) | |
334 set (hg, properties{:}); | |
335 endif | |
336 endfor | |
318 endif | 337 endif |
319 | 338 |
320 set (gca (), "view", [-37.5, 30]); | 339 set (gca (), "view", [-37.5, 30]); |
321 | 340 |
322 if (nargout > 0 && idx > 0) | 341 if (nargout > 0 && idx > 0) |