7017
|
1 ## Copyright (C) 2005, 2007 John W. Eaton |
6405
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
6405
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
6405
|
18 |
6895
|
19 ## Undocumented internal function. |
6405
|
20 |
|
21 ## Author: jwe |
|
22 |
7269
|
23 function __go_draw_axes__ (h, plot_stream, enhanced, mono) |
6405
|
24 |
7269
|
25 if (nargin == 4) |
6405
|
26 |
|
27 axis_obj = get (h); |
|
28 |
|
29 parent_figure_obj = get (axis_obj.parent); |
|
30 |
6413
|
31 persistent have_newer_gnuplot ... |
|
32 = compare_versions (__gnuplot_version__ (), "4.0", ">"); |
6405
|
33 |
|
34 ## Set axis properties here? |
7191
|
35 pos = [0, 0, 1, 1]; |
7240
|
36 if (strcmp (axis_obj.activepositionproperty, "outerposition")) |
|
37 ymirror = true; |
|
38 if (! isempty (axis_obj.outerposition)) |
|
39 pos = axis_obj.outerposition; |
|
40 endif |
|
41 else |
7206
|
42 ymirror = false; |
7240
|
43 if (! isempty (axis_obj.position)) |
|
44 pos = axis_obj.position; |
|
45 fprintf (plot_stream, "set tmargin 0;\n"); |
|
46 fprintf (plot_stream, "set bmargin 0;\n"); |
|
47 fprintf (plot_stream, "set lmargin 0;\n"); |
|
48 fprintf (plot_stream, "set rmargin 0;\n"); |
|
49 endif |
6405
|
50 endif |
|
51 |
7189
|
52 if (! strcmp (axis_obj.__colorbar__, "none")) |
|
53 [pos, cbox_orient, cbox_size, cbox_origin, cbox_mirror] = ... |
|
54 gnuplot_postion_colorbox (pos, axis_obj.__colorbar__); |
|
55 endif |
|
56 |
|
57 fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2)); |
|
58 fprintf (plot_stream, "set size %.15g, %.15g;\n", pos(3), pos(4)); |
|
59 |
6758
|
60 if (strcmpi (axis_obj.dataaspectratiomode, "manual")) |
6405
|
61 r = axis_obj.dataaspectratio; |
6914
|
62 fprintf (plot_stream, "set size ratio %.15g;\n", -r(2)/r(1)); |
6405
|
63 else |
|
64 fputs (plot_stream, "set size noratio;\n"); |
|
65 endif |
|
66 |
7189
|
67 fputs (plot_stream, "set pm3d;\n"); |
6778
|
68 fputs (plot_stream, "unset label;\n"); |
|
69 |
6405
|
70 if (! isempty (axis_obj.title)) |
|
71 t = get (axis_obj.title); |
|
72 if (isempty (t.string)) |
|
73 fputs (plot_stream, "unset title;\n"); |
|
74 else |
7189
|
75 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", |
|
76 have_newer_gnuplot); |
7257
|
77 if (strcmp (f, "*")) |
|
78 fontspec = ""; |
|
79 else |
|
80 fontspec = sprintf ("font \"%s,%d\"", f, s); |
|
81 endif |
|
82 fprintf (plot_stream, "set title \"%s\" %s;\n", |
|
83 undo_string_escapes (tt), fontspec); |
6405
|
84 endif |
|
85 endif |
|
86 |
|
87 if (! isempty (axis_obj.xlabel)) |
|
88 t = get (axis_obj.xlabel); |
6737
|
89 angle = t.rotation; |
7269
|
90 colorspec = get_text_colorspec (axis_obj.xcolor, mono); |
6405
|
91 if (isempty (t.string)) |
7194
|
92 fprintf (plot_stream, "unset xlabel;\n"); |
|
93 fprintf (plot_stream, "unset x2label;\n"); |
6405
|
94 else |
7189
|
95 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", |
|
96 have_newer_gnuplot); |
7257
|
97 if (strcmp (f, "*")) |
|
98 fontspec = ""; |
|
99 else |
|
100 fontspec = sprintf ("font \"%s,%d\"", f, s); |
|
101 endif |
7194
|
102 if (strcmpi (axis_obj.xaxislocation, "top")) |
7257
|
103 fprintf (plot_stream, "set x2label \"%s\" %s %s", |
|
104 undo_string_escapes (tt), colorspec, fontspec); |
7194
|
105 else |
7257
|
106 fprintf (plot_stream, "set xlabel \"%s\" %s %s", |
|
107 undo_string_escapes (tt), colorspec, fontspec); |
7194
|
108 endif |
6738
|
109 if (have_newer_gnuplot) |
|
110 ## Rotation of xlabel not yet support by gnuplot as of 4.2, but |
|
111 ## there is no message about it. |
|
112 fprintf (plot_stream, " rotate by %f", angle); |
|
113 endif |
|
114 fputs (plot_stream, ";\n"); |
7194
|
115 if (strcmpi (axis_obj.xaxislocation, "top")) |
|
116 fprintf (plot_stream, "unset xlabel;\n"); |
|
117 else |
|
118 fprintf (plot_stream, "unset x2label;\n"); |
|
119 endif |
6405
|
120 endif |
|
121 endif |
|
122 |
|
123 if (! isempty (axis_obj.ylabel)) |
|
124 t = get (axis_obj.ylabel); |
6737
|
125 angle = t.rotation; |
7269
|
126 colorspec = get_text_colorspec (axis_obj.ycolor, mono); |
6405
|
127 if (isempty (t.string)) |
7194
|
128 fprintf (plot_stream, "unset ylabel;\n"); |
|
129 fprintf (plot_stream, "unset y2label;\n"); |
6405
|
130 else |
7189
|
131 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", |
|
132 have_newer_gnuplot); |
7257
|
133 if (strcmp (f, "*")) |
|
134 fontspec = ""; |
|
135 else |
|
136 fontspec = sprintf ("font \"%s,%d\"", f, s); |
|
137 endif |
7194
|
138 if (strcmpi (axis_obj.yaxislocation, "right")) |
7257
|
139 fprintf (plot_stream, "set y2label \"%s\" %s %s", |
|
140 undo_string_escapes (tt), colorspec, fontspec); |
7194
|
141 else |
7257
|
142 fprintf (plot_stream, "set ylabel \"%s\" %s %s", |
|
143 undo_string_escapes (tt), colorspec, fontspec); |
7194
|
144 endif |
6738
|
145 if (have_newer_gnuplot) |
6766
|
146 fprintf (plot_stream, " rotate by %f;\n", angle); |
6738
|
147 endif |
|
148 fputs (plot_stream, ";\n"); |
7194
|
149 if (strcmpi (axis_obj.yaxislocation, "right")) |
|
150 fprintf (plot_stream, "unset ylabel;\n"); |
|
151 else |
|
152 fprintf (plot_stream, "unset y2label;\n"); |
|
153 endif |
6405
|
154 endif |
|
155 endif |
|
156 |
|
157 if (! isempty (axis_obj.zlabel)) |
|
158 t = get (axis_obj.zlabel); |
6737
|
159 angle = t.rotation; |
7269
|
160 colorspec = get_text_colorspec (axis_obj.zcolor, mono); |
6405
|
161 if (isempty (t.string)) |
|
162 fputs (plot_stream, "unset zlabel;\n"); |
|
163 else |
7189
|
164 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", |
|
165 have_newer_gnuplot); |
7257
|
166 if (strcmp (f, "*")) |
|
167 fontspec = ""; |
|
168 else |
|
169 fontspec = sprintf ("font \"%s,%d\"", f, s); |
|
170 endif |
|
171 fprintf (plot_stream, "set zlabel \"%s\" %s %s", |
|
172 undo_string_escapes (tt), colorspec, fontspec); |
6738
|
173 if (have_newer_gnuplot) |
|
174 ## Rotation of zlabel not yet support by gnuplot as of 4.2, but |
|
175 ## there is no message about it. |
|
176 fprintf (plot_stream, " rotate by %f;\n", angle); |
|
177 endif |
|
178 fputs (plot_stream, ";\n"); |
6405
|
179 endif |
|
180 endif |
|
181 |
6809
|
182 if (strcmpi (axis_obj.xaxislocation, "top")) |
|
183 xaxisloc = "x2"; |
|
184 xaxisloc_using = "x2"; |
|
185 else |
|
186 xaxisloc = "x"; |
|
187 xaxisloc_using = "x1"; |
|
188 endif |
|
189 if (strcmpi (axis_obj.yaxislocation, "right")) |
|
190 yaxisloc = "y2"; |
|
191 yaxisloc_using = "y2"; |
|
192 else |
|
193 yaxisloc = "y"; |
|
194 yaxisloc_using = "y1"; |
|
195 endif |
|
196 |
7274
|
197 have_grid = false; |
|
198 |
6758
|
199 if (strcmpi (axis_obj.xgrid, "on")) |
7274
|
200 have_grid = true; |
6809
|
201 fprintf (plot_stream, "set grid %stics;\n", xaxisloc); |
6405
|
202 else |
6809
|
203 fprintf (plot_stream, "set grid no%stics;\n", xaxisloc); |
6405
|
204 endif |
|
205 |
6758
|
206 if (strcmpi (axis_obj.ygrid, "on")) |
7274
|
207 have_grid = true; |
6809
|
208 fprintf (plot_stream, "set grid %stics;\n", yaxisloc); |
6405
|
209 else |
6809
|
210 fprintf (plot_stream, "set grid no%stics;\n", yaxisloc); |
6405
|
211 endif |
|
212 |
6758
|
213 if (strcmpi (axis_obj.zgrid, "on")) |
7274
|
214 have_grid = true; |
6405
|
215 fputs (plot_stream, "set grid ztics;\n"); |
|
216 else |
7085
|
217 fputs (plot_stream, "set grid noztics;\n"); |
6405
|
218 endif |
|
219 |
6758
|
220 if (strcmpi (axis_obj.xminorgrid, "on")) |
7274
|
221 have_grid = true; |
6809
|
222 fprintf (plot_stream, "set m%stics 5;\n", xaxisloc); |
|
223 fprintf (plot_stream, "set grid m%stics;\n", xaxisloc); |
6405
|
224 else |
6809
|
225 fprintf (plot_stream, "set grid nom%stics;\n", xaxisloc); |
6405
|
226 endif |
|
227 |
6758
|
228 if (strcmpi (axis_obj.yminorgrid, "on")) |
7274
|
229 have_grid = true; |
6809
|
230 fprintf (plot_stream, "set m%stics 5;\n", yaxisloc); |
|
231 fprintf (plot_stream, "set grid m%stics;\n", yaxisloc); |
6405
|
232 else |
6809
|
233 fprintf (plot_stream, "set grid nom%stics;\n", yaxisloc); |
6405
|
234 endif |
|
235 |
6758
|
236 if (strcmpi (axis_obj.zminorgrid, "on")) |
7274
|
237 have_grid = true; |
6405
|
238 fputs (plot_stream, "set mztics 5;\n"); |
|
239 fputs (plot_stream, "set grid mztics;\n"); |
|
240 else |
|
241 fputs (plot_stream, "set grid nomztics;\n"); |
|
242 endif |
|
243 |
7274
|
244 if (have_grid) |
|
245 fputs (plot_stream, "set grid front;\n"); |
|
246 endif |
|
247 |
7269
|
248 do_tics (axis_obj, plot_stream, ymirror, mono); |
6405
|
249 |
6758
|
250 xlogscale = strcmpi (axis_obj.xscale, "log"); |
6405
|
251 if (xlogscale) |
6809
|
252 fprintf (plot_stream, "set logscale %s;\n", xaxisloc); |
6405
|
253 else |
6809
|
254 fprintf (plot_stream, "unset logscale %s;\n", xaxisloc); |
6405
|
255 endif |
|
256 |
6758
|
257 ylogscale = strcmpi (axis_obj.yscale, "log"); |
6405
|
258 if (ylogscale) |
6809
|
259 fprintf (plot_stream, "set logscale %s;\n", yaxisloc); |
6405
|
260 else |
6809
|
261 fprintf (plot_stream, "unset logscale %s;\n", yaxisloc); |
6405
|
262 endif |
|
263 |
6758
|
264 zlogscale = strcmpi (axis_obj.zscale, "log"); |
6405
|
265 if (zlogscale) |
|
266 fputs (plot_stream, "set logscale z;\n"); |
|
267 else |
|
268 fputs (plot_stream, "unset logscale z;\n"); |
|
269 endif |
|
270 |
6758
|
271 xautoscale = strcmpi (axis_obj.xlimmode, "auto"); |
|
272 yautoscale = strcmpi (axis_obj.ylimmode, "auto"); |
|
273 zautoscale = strcmpi (axis_obj.zlimmode, "auto"); |
7109
|
274 cautoscale = strcmpi (axis_obj.climmode, "auto"); |
6405
|
275 |
|
276 kids = axis_obj.children; |
|
277 |
|
278 nd = 0; |
|
279 data_idx = 0; |
|
280 data = cell (); |
6464
|
281 is_image_data = []; |
7175
|
282 hidden_removal = NaN; |
7271
|
283 view_map = false; |
6405
|
284 |
7223
|
285 xlim = axis_obj.xlim; |
|
286 ylim = axis_obj.ylim; |
|
287 zlim = axis_obj.zlim; |
|
288 clim = axis_obj.clim; |
6405
|
289 |
7222
|
290 if (! cautoscale && clim(1) == clim(2)) |
|
291 clim(2)++; |
7189
|
292 endif |
|
293 |
6405
|
294 [view_cmd, view_fcn, view_zoom] = image_viewer (); |
|
295 use_gnuplot_for_images = (ischar (view_fcn) |
|
296 && strcmp (view_fcn, "gnuplot_internal")); |
|
297 |
|
298 ximg_data = {}; |
|
299 ximg_data_idx = 0; |
|
300 |
|
301 for i = 1:length (kids) |
|
302 |
|
303 obj = get (kids(i)); |
|
304 |
|
305 switch (obj.type) |
|
306 case "image" |
|
307 ## FIXME - Is there a better way to determine if the plot |
|
308 ## command should be "plot" or "splot"????? Could have images |
|
309 ## projected into 3D so there is really no reason to limit |
|
310 ## this. |
|
311 if (nd == 0) |
|
312 nd = 2; |
|
313 endif |
|
314 |
|
315 img_data = obj.cdata; |
|
316 img_xdata = obj.xdata; |
|
317 img_ydata = obj.ydata; |
|
318 |
|
319 if (use_gnuplot_for_images) |
|
320 |
7271
|
321 fputs (plot_stream, "set border front;\n"); |
6405
|
322 data_idx++; |
6464
|
323 is_image_data(data_idx) = true; |
6861
|
324 parametric(data_idx) = false; |
7119
|
325 have_cdata(data_idx) = false; |
6405
|
326 |
|
327 [y_dim, x_dim] = size (img_data(:,:,1)); |
|
328 if (x_dim > 1) |
|
329 dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1); |
|
330 else |
|
331 dx = 1; |
|
332 endif |
|
333 if (y_dim > 1) |
|
334 dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1); |
|
335 else |
|
336 dy = 1; |
|
337 endif |
|
338 x_origin = min (img_xdata); |
|
339 y_origin = min (img_ydata); |
|
340 |
|
341 if (ndims (img_data) == 3) |
6464
|
342 data{data_idx} = permute (img_data, [3, 1, 2])(:); |
6405
|
343 format = "1:2:3"; |
|
344 imagetype = "rgbimage"; |
|
345 else |
6464
|
346 data{data_idx} = img_data(:); |
6405
|
347 format = "1"; |
|
348 imagetype = "image"; |
|
349 endif |
|
350 |
6579
|
351 titlespec{data_idx} = "title \"\""; |
6914
|
352 usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx origin=(%.15g,%.15g) dx=%.15g dy=%.15g using %s", |
6405
|
353 x_dim, y_dim, x_origin, y_origin, dx, dy, format); |
|
354 withclause{data_idx} = sprintf ("with %s", imagetype); |
|
355 |
|
356 else |
|
357 ximg_data{++ximg_data_idx} = img_data; |
|
358 endif |
|
359 |
|
360 case "line" |
7120
|
361 if (strncmp (obj.linestyle, "none", 4) |
|
362 && (! isfield (obj, "marker") |
|
363 || (isfield (obj, "marker") |
|
364 && strncmp (obj.marker, "none", 4)))) |
|
365 continue; |
|
366 endif |
6405
|
367 data_idx++; |
6464
|
368 is_image_data(data_idx) = false; |
6861
|
369 parametric(data_idx) = true; |
7119
|
370 have_cdata(data_idx) = false; |
6405
|
371 if (isempty (obj.keylabel)) |
|
372 titlespec{data_idx} = "title \"\""; |
|
373 else |
7189
|
374 tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "keylabel", have_newer_gnuplot)); |
7094
|
375 titlespec{data_idx} = strcat ("title \"", tmp, "\""); |
6405
|
376 endif |
7269
|
377 [style, typ, with] = do_linestyle_command (obj, data_idx, |
|
378 mono, plot_stream); |
6405
|
379 usingclause{data_idx} = ""; |
6425
|
380 if (have_newer_gnuplot || isnan (typ)) |
|
381 withclause{data_idx} = sprintf ("with %s linestyle %d", |
|
382 style, data_idx); |
|
383 else |
|
384 withclause{data_idx} = sprintf ("with %s linetype %d", |
|
385 style, typ); |
|
386 endif |
6405
|
387 if (! isempty (obj.zdata)) |
|
388 nd = 3; |
|
389 xdat = obj.xdata(:); |
|
390 ydat = obj.ydata(:); |
|
391 zdat = obj.zdata(:); |
7119
|
392 |
6405
|
393 data{data_idx} = [xdat, ydat, zdat]'; |
|
394 usingclause{data_idx} = "using ($1):($2):($3)"; |
|
395 fputs (plot_stream, "set parametric;\n"); |
|
396 fputs (plot_stream, "set style data lines;\n"); |
|
397 fputs (plot_stream, "set surface;\n"); |
|
398 fputs (plot_stream, "unset contour;\n"); |
|
399 else |
|
400 nd = 2; |
|
401 xdat = obj.xdata(:); |
|
402 ydat = obj.ydata(:); |
|
403 ldat = obj.ldata; |
|
404 yerr = xerr = false; |
|
405 if (! isempty (ldat)) |
|
406 yerr = true; |
|
407 ldat = ldat(:); |
|
408 endif |
|
409 udat = obj.udata; |
|
410 if (! isempty (udat)) |
|
411 udat = udat(:); |
|
412 endif |
|
413 xldat = obj.xldata; |
|
414 if (! isempty (xldat)) |
|
415 xerr = true; |
|
416 xldat = xldat(:); |
|
417 endif |
|
418 xudat = obj.xudata; |
|
419 if (! isempty (xudat)) |
|
420 xudat = xudat(:); |
|
421 endif |
|
422 if (yerr) |
7213
|
423 if (isempty (ldat)) |
|
424 ylo = ydat; |
|
425 else |
|
426 ylo = ydat-ldat; |
|
427 endif |
|
428 if (isempty (udat)) |
|
429 yhi = ydat; |
|
430 else |
|
431 yhi = ydat+udat; |
|
432 endif |
6405
|
433 if (xerr) |
7213
|
434 if (isempty (xldat)) |
|
435 xlo = xdat; |
|
436 else |
|
437 xlo = xdat-xldat; |
|
438 endif |
|
439 if (isempty (xudat)) |
|
440 xhi = xdat; |
|
441 else |
|
442 xhi = xdat+xudat; |
|
443 endif |
6405
|
444 data{data_idx} = [xdat, ydat, xlo, xhi, ylo, yhi]'; |
|
445 usingclause{data_idx} = "using ($1):($2):($3):($4):($5):($6)"; |
6908
|
446 withclause{data_idx} = "with xyerrorbars"; |
6405
|
447 else |
|
448 data{data_idx} = [xdat, ydat, ylo, yhi]'; |
|
449 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
6908
|
450 withclause{data_idx} = "with yerrorbars"; |
6405
|
451 endif |
|
452 elseif (xerr) |
7236
|
453 if (isempty (xldat)) |
|
454 xlo = xdat; |
|
455 else |
|
456 xlo = xdat-xldat; |
|
457 endif |
|
458 if (isempty (xudat)) |
|
459 xhi = xdat; |
|
460 else |
|
461 xhi = xdat+xudat; |
|
462 endif |
6405
|
463 data{data_idx} = [xdat, ydat, xlo, xhi]'; |
|
464 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
6908
|
465 withclause{data_idx} = "with xerrorbars"; |
6405
|
466 else |
|
467 data{data_idx} = [xdat, ydat]'; |
6809
|
468 usingclause{data_idx} = sprintf ("using ($1):($2) axes %s%s", |
|
469 xaxisloc_using, yaxisloc_using); |
6405
|
470 endif |
|
471 endif |
6465
|
472 if (! (have_newer_gnuplot || isempty (with))) |
|
473 if (isempty (withclause{data_idx})) |
6809
|
474 withclause{data_idx} = sprintf ("with %s", with); |
6465
|
475 else |
6809
|
476 withclause{data_idx} = sprintf ("%s %s", withclause{data_idx}, |
|
477 with); |
6465
|
478 endif |
|
479 endif |
6405
|
480 |
6790
|
481 case "patch" |
6885
|
482 cmap = parent_figure_obj.colormap; |
7020
|
483 [nr, nc] = size (obj.xdata); |
|
484 |
7189
|
485 if (! isempty (obj.cdata)) |
|
486 cdat = obj.cdata; |
|
487 else |
|
488 cdat = []; |
|
489 endif |
|
490 |
7170
|
491 for i = 1:nc |
7020
|
492 xcol = obj.xdata(:,i); |
|
493 ycol = obj.ydata(:,i); |
7170
|
494 if (! isempty (obj.zdata)) |
|
495 zcol = obj.zdata(:,i); |
|
496 else |
|
497 zcol = []; |
|
498 endif |
7020
|
499 |
|
500 if (! isnan (xcol) && ! isnan (ycol)) |
|
501 ## Is the patch closed or not |
7175
|
502 if (strncmp (obj.facecolor, "none", 4)) |
|
503 if (isnan (hidden_removal)) |
|
504 hidden_removal = false; |
|
505 endif |
|
506 else |
|
507 hidden_removal = true; |
7170
|
508 if (! isempty (zcol)) |
|
509 error ("gnuplot (as of v4.2) only supports 2D filled patches"); |
|
510 else |
|
511 nd = 2; |
|
512 endif |
|
513 |
|
514 data_idx++; |
|
515 is_image_data(data_idx) = false; |
|
516 parametric(data_idx) = false; |
|
517 have_cdata(data_idx) = false; |
|
518 if (i > 1 || isempty (obj.keylabel)) |
|
519 titlespec{data_idx} = "title \"\""; |
|
520 else |
7189
|
521 tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "keylabel", have_newer_gnuplot)); |
7170
|
522 titlespec{data_idx} = strcat ("title \"", tmp, "\""); |
|
523 endif |
|
524 usingclause{data_idx} = ""; |
7189
|
525 if (isfield (obj, "facecolor")) |
|
526 if ((strncmp (obj.facecolor, "flat", 4) |
7284
|
527 || strncmp (obj.facecolor, "interp", 6)) |
|
528 && isfield (obj, "cdata")) |
7170
|
529 if (ndims (obj.cdata) == 2 |
7189
|
530 && (size (obj.cdata, 2) == nc |
|
531 && (size (obj.cdata, 1) == 1 |
|
532 || size (obj.cdata, 1) == 3))) |
|
533 ccol = cdat (:, i); |
|
534 elseif (ndims (obj.cdata) == 2 |
|
535 && (size (obj.cdata, 1) == nc |
|
536 && (size (obj.cdata, 2) == 1 |
|
537 || size (obj.cdata, 2) == 3))) |
|
538 ccol = cdat (i, :); |
7170
|
539 elseif (ndims (obj.cdata) == 3) |
7189
|
540 ccol = permute (cdat (:, i, :), [1, 3, 2]); |
7170
|
541 else |
7189
|
542 ccol = cdat; |
7170
|
543 endif |
|
544 if (strncmp (obj.facecolor, "flat", 4)) |
|
545 if (numel(ccol) == 3) |
|
546 color = ccol; |
|
547 else |
7226
|
548 r = 1 + round ((size (cmap, 1) - 1) |
|
549 * (ccol - clim(1))/(clim(2) - clim(1))); |
7170
|
550 r = max (1, min (r, size (cmap, 1))); |
|
551 color = cmap(r, :); |
|
552 endif |
|
553 elseif (strncmp (obj.facecolor, "interp", 6)) |
|
554 warning ("\"interp\" not supported, using 1st entry of cdata") |
|
555 r = 1 + round ((size (cmap, 1) - 1) * ccol(1)); |
|
556 r = max (1, min (r, size (cmap, 1))); |
|
557 color = cmap(r,:); |
|
558 endif |
7189
|
559 elseif (isnumeric (obj.facecolor)) |
|
560 color = obj.facecolor; |
7170
|
561 else |
7189
|
562 color = [0, 1, 0]; |
7170
|
563 endif |
|
564 else |
|
565 color = [0, 1, 0]; |
|
566 endif |
|
567 |
|
568 if (have_newer_gnuplot) |
7269
|
569 if (mono) |
|
570 colorspec = ""; |
|
571 else |
|
572 colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", |
|
573 round (255*color)); |
|
574 endif |
|
575 withclause{data_idx} = sprintf ("with filledcurve %s", |
|
576 colorspec); |
7170
|
577 else |
|
578 if (isequal (color, [0,0,0])) |
|
579 typ = -1; |
|
580 elseif (isequal (color, [1,0,0])) |
|
581 typ = 1; |
|
582 elseif (isequal (color, [0,1,0])) |
|
583 typ = 2; |
|
584 elseif (isequal (color, [0,0,1])) |
|
585 typ = 3; |
|
586 elseif (isequal (color, [1,0,1])) |
|
587 typ = 4; |
|
588 elseif (isequal (color, [0,1,1])) |
|
589 typ = 5; |
|
590 elseif (isequal (color, [1,1,1])) |
|
591 typ = -1; |
|
592 elseif (isequal (color, [1,1,0])) |
|
593 typ = 7; |
|
594 else |
|
595 typ = -1; |
|
596 endif |
|
597 withclause{data_idx} = sprintf ("with filledcurve lt %d", typ); |
|
598 endif |
|
599 data{data_idx} = [xcol, ycol]'; |
|
600 usingclause{data_idx} = "using ($1):($2)"; |
|
601 endif |
|
602 endif |
|
603 |
|
604 ## patch outline |
|
605 if (! strncmp (obj.edgecolor, "none", 4)) |
|
606 if (! isempty (zcol)) |
|
607 nd = 3; |
7148
|
608 else |
7170
|
609 nd = 2; |
7148
|
610 endif |
7170
|
611 |
|
612 data_idx++; |
|
613 is_image_data(data_idx) = false; |
|
614 parametric(data_idx) = false; |
|
615 have_cdata(data_idx) = false; |
|
616 titlespec{data_idx} = "title \"\""; |
7020
|
617 usingclause{data_idx} = ""; |
7189
|
618 |
|
619 if (isfield (obj, "markersize")) |
|
620 mdat = obj.markersize; |
|
621 endif |
|
622 |
|
623 if (isfield (obj, "edgecolor")) |
|
624 if ((strncmp (obj.edgecolor, "flat", 4) |
7284
|
625 || strncmp (obj.edgecolor, "interp", 6)) |
|
626 && isfield (obj, "cdata")) |
7119
|
627 if (ndims (obj.cdata) == 2 |
7189
|
628 && (size (obj.cdata, 2) == nc |
|
629 && (size (obj.cdata, 1) == 1 |
|
630 || size (obj.cdata, 1) == 3))) |
|
631 ccol = cdat (:, i); |
|
632 elseif (ndims (obj.cdata) == 2 |
|
633 && (size (obj.cdata, 1) == nc |
|
634 && (size (obj.cdata, 2) == 1 |
|
635 || size (obj.cdata, 2) == 3))) |
|
636 ccol = cdat (i, :); |
7020
|
637 elseif (ndims (obj.cdata) == 3) |
7189
|
638 ccol = permute (cdat (:, i, :), [1, 3, 2]); |
7020
|
639 else |
7189
|
640 ccol = cdat; |
7020
|
641 endif |
7170
|
642 if (strncmp (obj.edgecolor, "flat", 4)) |
7189
|
643 if (numel(ccol) == 3) |
7020
|
644 color = ccol; |
|
645 else |
7226
|
646 r = 1 + round ((size (cmap, 1) - 1) |
|
647 * (ccol - clim(1))/(clim(2) - clim(1))); |
7020
|
648 r = max (1, min (r, size (cmap, 1))); |
|
649 color = cmap(r, :); |
|
650 endif |
7170
|
651 elseif (strncmp (obj.edgecolor, "interp", 6)) |
7020
|
652 warning ("\"interp\" not supported, using 1st entry of cdata") |
|
653 r = 1 + round ((size (cmap, 1) - 1) * ccol(1)); |
|
654 r = max (1, min (r, size (cmap, 1))); |
|
655 color = cmap(r,:); |
|
656 endif |
7189
|
657 elseif (isnumeric (obj.edgecolor)) |
|
658 color = obj.edgecolor; |
|
659 else |
|
660 color = [0, 0, 0]; |
7020
|
661 endif |
|
662 else |
7189
|
663 color = [0, 0, 0]; |
7020
|
664 endif |
7189
|
665 |
|
666 if (isfield (obj, "linestyle")) |
|
667 switch (obj.linestyle) |
|
668 case "-" |
|
669 lt = "1"; |
|
670 case "--" |
|
671 lt = "2"; |
|
672 case ":" |
|
673 lt = "3"; |
|
674 case "-." |
|
675 lt = "6"; |
|
676 case "none" |
|
677 lt = ""; |
|
678 otherwise |
|
679 lt = ""; |
|
680 endswitch |
|
681 else |
|
682 lt = ""; |
|
683 endif |
|
684 |
|
685 if (isfield (obj, "marker")) |
|
686 if (isfield (obj, "marker")) |
|
687 switch (obj.marker) |
|
688 case "+" |
|
689 pt = "pt 1"; |
|
690 case "o" |
|
691 pt = "pt 6"; |
|
692 case "*" |
|
693 pt = "pt 3"; |
|
694 case "." |
|
695 pt = "pt 0"; |
|
696 case "x" |
|
697 pt = "pt 2"; |
|
698 case {"square", "s"} |
|
699 pt = "pt 5"; |
|
700 case {"diamond", "d"} |
|
701 pt = "pt 13"; |
|
702 case "^" |
|
703 pt = "pt 9"; |
|
704 case "v" |
|
705 pt = "pt 11"; |
|
706 case ">" |
|
707 pt = "pt 8"; |
|
708 case "<" |
|
709 pt = "pt 10"; |
|
710 case {"pentagram", "p"} |
|
711 pt = "pt 4"; |
|
712 case {"hexagram", "h"} |
|
713 pt = "pt 12"; |
|
714 case "none" |
|
715 pt = ""; |
|
716 otherwise |
|
717 pt = ""; |
|
718 endswitch |
|
719 endif |
|
720 else |
|
721 pt = ""; |
|
722 endif |
|
723 |
|
724 style = "lines"; |
|
725 if (isempty (lt)) |
|
726 if (! isempty (pt)) |
|
727 style = "points"; |
|
728 endif |
|
729 elseif (! isempty (pt)) |
|
730 style = "linespoints"; |
|
731 endif |
|
732 |
|
733 if (isfield (obj, "markersize")) |
|
734 if (length (mdat) == nc) |
|
735 m = mdat(i); |
|
736 else |
|
737 m = mdat; |
|
738 endif |
|
739 if (! strcmpi (style, "lines")) |
|
740 if (have_newer_gnuplot) |
|
741 ps = sprintf("pointsize %f", m); |
|
742 else |
|
743 ps = sprintf("ps %f", m); |
|
744 endif |
|
745 else |
|
746 ps = ""; |
|
747 endif |
|
748 else |
|
749 ps = ""; |
|
750 endif |
|
751 |
7020
|
752 if (have_newer_gnuplot) |
7269
|
753 if (mono) |
|
754 colorspec = ""; |
|
755 else |
|
756 colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", |
|
757 round (255*color)); |
|
758 endif |
|
759 withclause{data_idx} = sprintf ("with %s %s %s %s", |
|
760 style, pt, ps, colorspec); |
7020
|
761 else |
|
762 if (isequal (color, [0,0,0])) |
|
763 typ = -1; |
|
764 elseif (isequal (color, [1,0,0])) |
|
765 typ = 1; |
|
766 elseif (isequal (color, [0,1,0])) |
|
767 typ = 2; |
|
768 elseif (isequal (color, [0,0,1])) |
|
769 typ = 3; |
|
770 elseif (isequal (color, [1,0,1])) |
|
771 typ = 4; |
|
772 elseif (isequal (color, [0,1,1])) |
|
773 typ = 5; |
|
774 elseif (isequal (color, [1,1,1])) |
|
775 typ = -1; |
|
776 elseif (isequal (color, [1,1,0])) |
|
777 typ = 7; |
|
778 else |
|
779 typ = -1; |
|
780 endif |
7189
|
781 withclause{data_idx} = sprintf ("with %s %s %s lt %d", |
|
782 style, pt, ps, typ); |
7020
|
783 endif |
6790
|
784 |
7170
|
785 if (! isempty (zcol)) |
|
786 if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol)) |
|
787 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ... |
|
788 [zcol; zcol(1)]]'; |
|
789 else |
|
790 data{data_idx} = [xcol, ycol, zcol]'; |
|
791 endif |
|
792 usingclause{data_idx} = "using ($1):($2):($3)"; |
7020
|
793 else |
7170
|
794 if (! isnan (xcol) && ! isnan (ycol)) |
|
795 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]'; |
|
796 else |
|
797 data{data_idx} = [xcol, ycol]'; |
|
798 endif |
|
799 usingclause{data_idx} = "using ($1):($2)"; |
7020
|
800 endif |
6885
|
801 endif |
7020
|
802 endfor |
6790
|
803 |
6405
|
804 case "surface" |
7119
|
805 nd = 3; |
7271
|
806 view_map = true; |
7110
|
807 if (! (strncmp (obj.edgecolor, "none", 4) |
|
808 && strncmp (obj.facecolor, "none", 4))) |
7109
|
809 data_idx++; |
|
810 is_image_data(data_idx) = false; |
|
811 parametric(data_idx) = false; |
7119
|
812 have_cdata(data_idx) = true; |
7170
|
813 [style, typ, with] = do_linestyle_command (obj, data_idx, |
7269
|
814 mono, plot_stream); |
7109
|
815 if (isempty (obj.keylabel)) |
|
816 titlespec{data_idx} = "title \"\""; |
|
817 else |
7189
|
818 tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "keylabel", have_newer_gnuplot)); |
7109
|
819 titlespec{data_idx} = strcat ("title \"", tmp, "\""); |
|
820 endif |
|
821 usingclause{data_idx} = ""; |
|
822 if (have_newer_gnuplot || isnan (typ)) |
|
823 withclause{data_idx} = sprintf ("with %s linestyle %d", |
|
824 style, data_idx); |
6405
|
825 else |
7109
|
826 withclause{data_idx} = sprintf ("with %s linetype %d %s", |
|
827 style, typ, with); |
|
828 endif |
|
829 |
|
830 xdat = obj.xdata; |
|
831 ydat = obj.ydata; |
|
832 zdat = obj.zdata; |
|
833 cdat = obj.cdata; |
7110
|
834 |
7109
|
835 err = false; |
|
836 if (! size_equal(zdat, cdat)) |
6405
|
837 err = true; |
7109
|
838 endif |
|
839 if (isvector (xdat) && isvector (ydat) && ismatrix (zdat)) |
7110
|
840 if (rows (zdat) == length (ydat) |
|
841 && columns (zdat) == length (xdat)) |
7109
|
842 [xdat, ydat] = meshgrid (xdat, ydat); |
|
843 else |
|
844 err = true; |
|
845 endif |
|
846 elseif (ismatrix (xdat) && ismatrix (ydat) && ismatrix (zdat)) |
7292
|
847 if (! size_equal (xdat, ydat, zdat)) |
7109
|
848 err = true; |
|
849 endif |
|
850 else |
|
851 err = true; |
|
852 endif |
|
853 if (err) |
|
854 error ("__go_draw_axes__: invalid grid data"); |
6405
|
855 endif |
7109
|
856 xlen = columns (zdat); |
|
857 ylen = rows (zdat); |
|
858 if (xlen == columns (xdat) && xlen == columns (ydat) |
|
859 && ylen == rows (xdat) && ylen == rows (ydat)) |
|
860 len = 4 * xlen; |
|
861 zz = zeros (ylen, len); |
|
862 k = 1; |
|
863 for kk = 1:4:len |
|
864 zz(:,kk) = xdat(:,k); |
|
865 zz(:,kk+1) = ydat(:,k); |
|
866 zz(:,kk+2) = zdat(:,k); |
|
867 zz(:,kk+3) = cdat(:,k); |
|
868 k++; |
|
869 endfor |
7170
|
870 data{data_idx} = zz.'; |
7109
|
871 endif |
|
872 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
|
873 |
|
874 fputs (plot_stream, "unset parametric;\n"); |
|
875 fputs (plot_stream, "set style data lines;\n"); |
|
876 fputs (plot_stream, "set surface;\n"); |
|
877 fputs (plot_stream, "unset contour;\n"); |
|
878 |
7119
|
879 ## Interpolation does not work for flat surfaces (e.g. pcolor) |
|
880 ## and color mapping --> currently set empty. |
|
881 interp_str = ""; |
|
882 flat_interp_face = (strncmp (obj.facecolor, "flat", 4) |
|
883 || strncmp (obj.facecolor, "interp", 6)); |
|
884 flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4) |
|
885 || strncmp (obj.edgecolor, "interp", 6)); |
7154
|
886 |
|
887 facecolor_none_or_white = (strncmp (obj.facecolor, "none", 4) |
|
888 || (isnumeric (obj.facecolor) |
|
889 && all (obj.facecolor == 1))); |
7149
|
890 if (strncmp (obj.facecolor, "none", 4)) |
7175
|
891 if (isnan (hidden_removal)) |
|
892 hidden_removal = false; |
|
893 endif |
|
894 else |
|
895 hidden_removal = true; |
7149
|
896 endif |
|
897 |
7119
|
898 if (flat_interp_face |
7154
|
899 || (flat_interp_edge && facecolor_none_or_white)) |
7189
|
900 withclause{data_idx} = "with line palette"; |
7119
|
901 endif |
7109
|