6405
|
1 ## Copyright (C) 2005 John W. Eaton |
|
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 2, or (at your option) |
|
8 ## 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, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} __go_draw_axes__ (@var{axis_obj}, @var{plot_stream}) |
|
22 ## Display the axes @var{axis_obj} on @var{plot_stream}. |
|
23 ## @end deftypefn |
|
24 |
|
25 ## Author: jwe |
|
26 |
|
27 function __go_draw_axes__ (h, plot_stream) |
|
28 |
|
29 if (nargin == 2) |
|
30 |
|
31 axis_obj = get (h); |
|
32 |
|
33 parent_figure_obj = get (axis_obj.parent); |
|
34 |
6413
|
35 persistent have_newer_gnuplot ... |
|
36 = compare_versions (__gnuplot_version__ (), "4.0", ">"); |
6405
|
37 |
|
38 ## Set axis properties here? |
|
39 |
|
40 if (! isempty (axis_obj.outerposition)) |
|
41 pos = axis_obj.outerposition; |
|
42 fprintf (plot_stream, "set origin %g, %g;\n", pos(1), pos(2)); |
|
43 fprintf (plot_stream, "set size %g, %g;\n", pos(3), pos(4)); |
|
44 endif |
|
45 |
|
46 if (! isempty (axis_obj.position)) |
|
47 pos = axis_obj.position; |
|
48 fprintf (plot_stream, "set origin %g, %g;\n", pos(1), pos(2)); |
|
49 fprintf (plot_stream, "set size %g, %g;\n", pos(3), pos(4)); |
|
50 endif |
|
51 |
|
52 if (strcmp (axis_obj.dataaspectratiomode, "manual")) |
|
53 r = axis_obj.dataaspectratio; |
|
54 fprintf (plot_stream, "set size ratio %g;\n", -r(2)/r(1)); |
|
55 else |
|
56 fputs (plot_stream, "set size noratio;\n"); |
|
57 endif |
|
58 |
|
59 if (! isempty (axis_obj.title)) |
|
60 t = get (axis_obj.title); |
|
61 if (isempty (t.string)) |
|
62 fputs (plot_stream, "unset title;\n"); |
|
63 else |
|
64 fprintf (plot_stream, "set title \"%s\";\n", |
|
65 undo_string_escapes (t.string)); |
|
66 endif |
|
67 endif |
|
68 |
|
69 if (! isempty (axis_obj.xlabel)) |
|
70 t = get (axis_obj.xlabel); |
|
71 if (isempty (t.string)) |
|
72 fputs (plot_stream, "unset xlabel;\n"); |
|
73 else |
|
74 fprintf (plot_stream, "set xlabel \"%s\";\n", |
|
75 undo_string_escapes (t.string)); |
|
76 endif |
|
77 endif |
|
78 |
|
79 if (! isempty (axis_obj.ylabel)) |
|
80 t = get (axis_obj.ylabel); |
|
81 if (isempty (t.string)) |
|
82 fputs (plot_stream, "unset ylabel;\n"); |
|
83 else |
|
84 fprintf (plot_stream, "set ylabel \"%s\";\n", |
|
85 undo_string_escapes (t.string)); |
|
86 endif |
|
87 endif |
|
88 |
|
89 if (! isempty (axis_obj.zlabel)) |
|
90 t = get (axis_obj.zlabel); |
|
91 if (isempty (t.string)) |
|
92 fputs (plot_stream, "unset zlabel;\n"); |
|
93 else |
|
94 fprintf (plot_stream, "set zlabel \"%s\";\n", |
|
95 undo_string_escapes (t.string)); |
|
96 endif |
|
97 endif |
|
98 |
|
99 if (strcmp (axis_obj.xgrid, "on")) |
|
100 fputs (plot_stream, "set grid xtics;\n"); |
|
101 else |
|
102 fputs (plot_stream, "set grid noxtics;\n"); |
|
103 endif |
|
104 |
|
105 if (strcmp (axis_obj.ygrid, "on")) |
|
106 fputs (plot_stream, "set grid ytics;\n"); |
|
107 else |
|
108 fputs (plot_stream, "set grid noytics;\n"); |
|
109 endif |
|
110 |
|
111 if (strcmp (axis_obj.zgrid, "on")) |
|
112 fputs (plot_stream, "set grid ztics;\n"); |
|
113 else |
|
114 fputs (plot_stream, "set grid ztics;\n"); |
|
115 endif |
|
116 |
|
117 if (strcmp (axis_obj.xminorgrid, "on")) |
|
118 fputs (plot_stream, "set mxtics 5;\n"); |
|
119 fputs (plot_stream, "set grid mxtics;\n"); |
|
120 else |
|
121 fputs (plot_stream, "set grid nomxtics;\n"); |
|
122 endif |
|
123 |
|
124 if (strcmp (axis_obj.yminorgrid, "on")) |
|
125 fputs (plot_stream, "set mytics 5;\n"); |
|
126 fputs (plot_stream, "set grid mytics;\n"); |
|
127 else |
|
128 fputs (plot_stream, "set grid nomytics;\n"); |
|
129 endif |
|
130 |
|
131 if (strcmp (axis_obj.zminorgrid, "on")) |
|
132 fputs (plot_stream, "set mztics 5;\n"); |
|
133 fputs (plot_stream, "set grid mztics;\n"); |
|
134 else |
|
135 fputs (plot_stream, "set grid nomztics;\n"); |
|
136 endif |
|
137 |
|
138 if (strcmp (axis_obj.xtickmode, "manual")) |
|
139 xtic = axis_obj.xtick; |
|
140 if (isempty (xtic)) |
|
141 fputs (plot_stream, "unset xtics;\n"); |
|
142 else |
|
143 ## FIXME |
|
144 endif |
|
145 else |
|
146 fputs (plot_stream, "set xtics;\n"); |
|
147 endif |
|
148 |
|
149 if (strcmp (axis_obj.ytickmode, "manual")) |
|
150 ytic = axis_obj.ytick; |
|
151 if (isempty (ytic)) |
|
152 fputs (plot_stream, "unset ytics;\n"); |
|
153 else |
|
154 ## FIXME |
|
155 endif |
|
156 else |
|
157 fputs (plot_stream, "set ytics;\n"); |
|
158 endif |
|
159 |
|
160 if (strcmp (axis_obj.ztickmode, "manual")) |
|
161 ztic = axis_obj.ztick; |
|
162 if (isempty (ztic)) |
|
163 fputs (plot_stream, "unset ztics;\n"); |
|
164 else |
|
165 ## FIXME |
|
166 endif |
|
167 else |
|
168 fputs (plot_stream, "set ztics;\n"); |
|
169 endif |
|
170 |
|
171 if (strcmp (axis_obj.xticklabelmode, "manual")) |
|
172 ## FIXME -- we should be able to specify the actual tick labels, |
|
173 ## not just the format. |
|
174 xticlabel = axis_obj.xticklabel; |
|
175 fprintf (plot_stream, "set format x \"%s\";\n", xticlabel); |
|
176 else |
|
177 fputs (plot_stream, "set xtics;\n"); |
|
178 endif |
|
179 |
|
180 if (strcmp (axis_obj.yticklabelmode, "manual")) |
|
181 ## FIXME -- we should be able to specify the actual tick labels, |
|
182 ## not just the format. |
|
183 yticlabel = axis_obj.yticklabel; |
|
184 fprintf (plot_stream, "set format y \"%s\";\n", yticlabel); |
|
185 else |
|
186 fputs (plot_stream, "set ytics;\n"); |
|
187 endif |
|
188 |
|
189 if (strcmp (axis_obj.zticklabelmode, "manual")) |
|
190 ## FIXME -- we should be able to specify the actual tick labels, |
|
191 ## not just the format. |
|
192 zticlabel = axis_obj.zticklabel; |
|
193 fprintf (plot_stream, "set format z \"%s\";\n", zticlabel); |
|
194 else |
|
195 fputs (plot_stream, "set ztics;\n"); |
|
196 endif |
|
197 |
|
198 xlogscale = strcmp (axis_obj.xscale, "log"); |
|
199 if (xlogscale) |
|
200 fputs (plot_stream, "set logscale x;\n"); |
|
201 else |
|
202 fputs (plot_stream, "unset logscale x;\n"); |
|
203 endif |
|
204 |
|
205 ylogscale = strcmp (axis_obj.yscale, "log"); |
|
206 if (ylogscale) |
|
207 fputs (plot_stream, "set logscale y;\n"); |
|
208 else |
|
209 fputs (plot_stream, "unset logscale y;\n"); |
|
210 endif |
|
211 |
|
212 zlogscale = strcmp (axis_obj.zscale, "log"); |
|
213 if (zlogscale) |
|
214 fputs (plot_stream, "set logscale z;\n"); |
|
215 else |
|
216 fputs (plot_stream, "unset logscale z;\n"); |
|
217 endif |
|
218 |
|
219 xautoscale = strcmp (axis_obj.xlimmode, "auto"); |
|
220 yautoscale = strcmp (axis_obj.ylimmode, "auto"); |
|
221 zautoscale = strcmp (axis_obj.zlimmode, "auto"); |
|
222 |
|
223 kids = axis_obj.children; |
|
224 |
|
225 nd = 0; |
|
226 data_idx = 0; |
|
227 data = cell (); |
|
228 |
|
229 xminp = yminp = zminp = Inf; |
|
230 xmax = ymax = zmax = -Inf; |
|
231 xmin = ymin = zmin = Inf; |
|
232 |
|
233 palette_set = 0; |
|
234 |
|
235 [view_cmd, view_fcn, view_zoom] = image_viewer (); |
|
236 use_gnuplot_for_images = (ischar (view_fcn) |
|
237 && strcmp (view_fcn, "gnuplot_internal")); |
|
238 |
|
239 ximg_data = {}; |
|
240 ximg_data_idx = 0; |
|
241 |
|
242 for i = 1:length (kids) |
|
243 |
|
244 obj = get (kids(i)); |
|
245 |
|
246 switch (obj.type) |
|
247 case "image" |
|
248 ## FIXME - Is there a better way to determine if the plot |
|
249 ## command should be "plot" or "splot"????? Could have images |
|
250 ## projected into 3D so there is really no reason to limit |
|
251 ## this. |
|
252 if (nd == 0) |
|
253 nd = 2; |
|
254 endif |
|
255 |
|
256 img_data = obj.cdata; |
|
257 img_colormap = parent_figure_obj.colormap; |
|
258 img_xdata = obj.xdata; |
|
259 img_ydata = obj.ydata; |
|
260 |
|
261 if (use_gnuplot_for_images) |
|
262 |
|
263 data_idx++; |
|
264 |
|
265 [y_dim, x_dim] = size (img_data(:,:,1)); |
|
266 if (x_dim > 1) |
|
267 dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1); |
|
268 else |
|
269 dx = 1; |
|
270 endif |
|
271 if (y_dim > 1) |
|
272 dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1); |
|
273 else |
|
274 dy = 1; |
|
275 endif |
|
276 x_origin = min (img_xdata); |
|
277 y_origin = min (img_ydata); |
|
278 |
|
279 if (nd == 2) |
|
280 if (xautoscale) |
|
281 xmin = min (xmin, min (img_xdata) - dx/2); |
|
282 xmax = max (xmax, max (img_xdata) + dx/2); |
|
283 xminp = min (xminp, min (img_xdata((img_xdata - dx/2)>0)) - dx/2); |
|
284 endif |
|
285 if (yautoscale) |
|
286 ymin = min (ymin, min (img_ydata) - dy/2); |
|
287 ymax = max (ymax, max (img_ydata) + dy/2); |
|
288 yminp = min (yminp, min (img_ydata((img_ydata - dy/2)>0)) - dy/2); |
|
289 endif |
|
290 else |
|
291 ## Can have images in 3D, but the image routines don't seem |
|
292 ## to have a means of arbitrary projection. |
|
293 endif |
|
294 |
|
295 ## Let the file be deleted when Octave exits or `purge_tmp_files' |
|
296 ## is called. |
|
297 [img_fid, img_fname] = mkstemp (fullfile (P_tmpdir, "gpimageXXXXXX"), 1); |
|
298 if (ndims (img_data) == 3) |
|
299 fwrite (img_fid, permute (img_data, [3, 1, 2])(:), "float"); |
|
300 format = "1:2:3"; |
|
301 imagetype = "rgbimage"; |
|
302 else |
|
303 fwrite (img_fid, img_data(:), "float"); |
|
304 format = "1"; |
|
305 imagetype = "image"; |
|
306 ## Only need to set pallete once because it doesn't change |
|
307 ## on a figure. |
|
308 if (! palette_set) |
|
309 palette_set = 1; |
|
310 palette_size = rows (img_colormap); |
|
311 fprintf (plot_stream, |
|
312 "set palette positive color model RGB maxcolors %i;\n", |
|
313 palette_size); |
|
314 if (palette_size <= 128) |
|
315 ## Break up command to avoid buffer overflow. |
|
316 fprintf (plot_stream, "set palette file \"-\" using 1:2:3:4;\n"); |
|
317 for i = 1:palette_size |
|
318 fprintf (plot_stream, "%g %g %g %g;\n", |
|
319 1e-3*round (1e3*[(i-1)/(palette_size-1), img_colormap(i,:)])); |
|
320 endfor |
|
321 fprintf (plot_stream, "e;\n"); |
|
322 else |
|
323 ## Let the file be deleted when Octave exits or |
|
324 ## `purge_tmp_files' is called. |
|
325 [cmap_fid, cmap_fname, msg] = mkstemp (fullfile (P_tmpdir, "gpimageXXXXXX"), 1); |
|
326 fwrite (cmap_fid, img_colormap', "float32", 0, "ieee-le"); |
|
327 fclose (cmap_fid); |
|
328 fprintf (plot_stream, |
|
329 "set palette file \"%s\" binary record=%d using 1:2:3;\n", |
|
330 cmap_fname, palette_size); |
|
331 endif |
|
332 endif |
|
333 endif |
|
334 fclose (img_fid); |
|
335 |
|
336 filespec{data_idx} = img_fname; |
|
337 titlespec{data_idx} = ""; |
6420
|
338 usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx origin=(%g,%g) dx=%g dy=%g using %s", |
6405
|
339 x_dim, y_dim, x_origin, y_origin, dx, dy, format); |
|
340 withclause{data_idx} = sprintf ("with %s", imagetype); |
|
341 |
|
342 ## Data in file, set to zero for data available test to pass |
|
343 ## below. |
|
344 data{data_idx} = 0; |
|
345 |
|
346 else |
|
347 ximg_data{++ximg_data_idx} = img_data; |
|
348 endif |
|
349 |
|
350 case "line" |
|
351 data_idx++; |
6431
|
352 filespec{data_idx} = "-"; |
6405
|
353 if (isempty (obj.keylabel)) |
|
354 titlespec{data_idx} = "title \"\""; |
|
355 else |
|
356 titlespec{data_idx} = strcat ("title \"", obj.keylabel, "\""); |
|
357 endif |
6425
|
358 [style, typ] = do_linestyle_command (obj, data_idx, plot_stream); |
6405
|
359 usingclause{data_idx} = ""; |
6425
|
360 if (have_newer_gnuplot || isnan (typ)) |
|
361 withclause{data_idx} = sprintf ("with %s linestyle %d", |
|
362 style, data_idx); |
|
363 else |
|
364 withclause{data_idx} = sprintf ("with %s linetype %d", |
|
365 style, typ); |
|
366 endif |
6405
|
367 parametric(i) = true; |
|
368 if (! isempty (obj.zdata)) |
|
369 nd = 3; |
|
370 xdat = obj.xdata(:); |
|
371 ydat = obj.ydata(:); |
|
372 zdat = obj.zdata(:); |
|
373 if (xautoscale) |
|
374 xmin = min (xmin, min (xdat)); |
|
375 xmax = max (xmax, max (xdat)); |
|
376 xminp = min (xminp, min (xdat(xdat>0))); |
|
377 endif |
|
378 if (yautoscale) |
|
379 ymin = min (ymin, min (ydat)); |
|
380 ymax = max (ymax, max (ydat)); |
|
381 yminp = min (yminp, min (ydat(ydat>0))); |
|
382 endif |
|
383 if (zautoscale) |
|
384 zmin = min (zmin, min (zdat)); |
|
385 zmax = max (zmax, max (zdat)); |
|
386 zminp = min (zminp, min (zdat(zdat>0))); |
|
387 endif |
|
388 data{data_idx} = [xdat, ydat, zdat]'; |
|
389 usingclause{data_idx} = "using ($1):($2):($3)"; |
|
390 fputs (plot_stream, "set parametric;\n"); |
|
391 fputs (plot_stream, "unset hidden3d;\n"); |
|
392 fputs (plot_stream, "set style data lines;\n"); |
|
393 fputs (plot_stream, "set surface;\n"); |
|
394 fputs (plot_stream, "unset contour;\n"); |
|
395 else |
|
396 nd = 2; |
|
397 xdat = obj.xdata(:); |
|
398 ydat = obj.ydata(:); |
|
399 ldat = obj.ldata; |
|
400 yerr = xerr = false; |
|
401 if (! isempty (ldat)) |
|
402 yerr = true; |
|
403 ldat = ldat(:); |
|
404 endif |
|
405 udat = obj.udata; |
|
406 if (! isempty (udat)) |
|
407 udat = udat(:); |
|
408 endif |
|
409 xldat = obj.xldata; |
|
410 if (! isempty (xldat)) |
|
411 xerr = true; |
|
412 xldat = xldat(:); |
|
413 endif |
|
414 xudat = obj.xudata; |
|
415 if (! isempty (xudat)) |
|
416 xudat = xudat(:); |
|
417 endif |
|
418 if (yerr) |
|
419 ylo = ydat-ldat; |
|
420 yhi = ydat+udat; |
|
421 if (yautoscale) |
|
422 ty = [ydat; ylo; yhi]; |
|
423 ymin = min (ymin, min (ty)); |
|
424 ymax = max (ymax, max (ty)); |
|
425 yminp = min (yminp, min (ty(ty>0))); |
|
426 endif |
|
427 if (xerr) |
|
428 xlo = xdat-xldat; |
|
429 xhi = xdat+xudat; |
|
430 if (xautoscale) |
|
431 tx = [xdat; xlo; xhi]; |
|
432 xmin = min (xmin, min (tx)); |
|
433 xmax = max (xmax, max (tx)); |
|
434 xminp = min (xminp, min (tx(tx>0))); |
|
435 endif |
|
436 data{data_idx} = [xdat, ydat, xlo, xhi, ylo, yhi]'; |
|
437 usingclause{data_idx} = "using ($1):($2):($3):($4):($5):($6)"; |
|
438 withclause{data_idx} = sprintf ("with xyerrorbars linestyle %d", |
|
439 data_idx); |
|
440 else |
|
441 if (xautoscale) |
|
442 xmin = min (xmin, min (xdat)); |
|
443 xmax = max (xmax, max (xdat)); |
|
444 xminp = min (xminp, min (tx(tx>0))); |
|
445 endif |
|
446 data{data_idx} = [xdat, ydat, ylo, yhi]'; |
|
447 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
|
448 withclause{data_idx} = sprintf ("with yerrorbars linestyle %d", |
|
449 data_idx); |
|
450 endif |
|
451 elseif (xerr) |
|
452 xlo = xdat-xldat; |
|
453 xhi = xdat+xudat; |
|
454 if (xautoscale) |
|
455 tx = [xdat; xlo; xhi]; |
|
456 xmin = min (xmin, min (tx)); |
|
457 xmax = max (xmax, max (tx)); |
|
458 xminp = min (xminp, min (tx(tx>0))); |
|
459 endif |
|
460 if (yautoscale) |
|
461 ymin = min (ymin, min (ydat)); |
|
462 ymax = max (ymax, max (ydat)); |
|
463 yminp = min (yminp, min (ty(ty>0))); |
|
464 endif |
|
465 data{data_idx} = [xdat, ydat, xlo, xhi]'; |
|
466 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
|
467 withclause{data_idx} = sprintf ("with xerrorbars linestyle %d", |
|
468 data_idx); |
|
469 else |
|
470 if (xautoscale) |
|
471 xmin = min (xmin, min (xdat)); |
|
472 xmax = max (xmax, max (xdat)); |
|
473 xminp = min (xminp, min (xdat(xdat>0))); |
|
474 endif |
|
475 if (yautoscale) |
|
476 ymin = min (ymin, min (ydat)); |
|
477 ymax = max (ymax, max (ydat)); |
|
478 yminp = min (yminp, min (ydat(ydat>0))); |
|
479 endif |
|
480 data{data_idx} = [xdat, ydat]'; |
|
481 usingclause{data_idx} = "using ($1):($2)"; |
|
482 endif |
|
483 endif |
|
484 |
|
485 case "surface" |
|
486 data_idx++; |
6425
|
487 [style, typ] = do_linestyle_command (obj, data_idx, plot_stream); |
6431
|
488 filespec{data_idx} = "-"; |
6405
|
489 if (isempty (obj.keylabel)) |
|
490 titlespec{data_idx} = "title \"\""; |
|
491 else |
|
492 titlespec{data_idx} = strcat ("title \"", obj.keylabel, "\""); |
|
493 endif |
|
494 usingclause{data_idx} = ""; |
6425
|
495 if (have_newer_gnuplot || isnan (typ)) |
|
496 withclause{data_idx} = sprintf ("with %s linestyle %d", |
|
497 style, data_idx); |
|
498 else |
|
499 withclause{data_idx} = sprintf ("with %s linetype %d", |
|
500 style, typ); |
|
501 endif |
6405
|
502 parametric(i) = false; |
|
503 nd = 3; |
|
504 xdat = obj.xdata; |
|
505 ydat = obj.ydata; |
|
506 zdat = obj.zdata; |
|
507 if (xautoscale) |
|
508 tx = xdat(:); |
|
509 xmin = min (xmin, min (tx)); |
|
510 xmax = max (xmax, max (tx)); |
|
511 xminp = min (xminp, min (tx(tx>0))); |
|
512 endif |
|
513 if (yautoscale) |
|
514 ty = ydat(:); |
|
515 ymin = min (ymin, min (ty)); |
|
516 ymax = max (ymax, max (ty)); |
|
517 yminp = min (yminp, min (ty(ty>0))); |
|
518 endif |
|
519 if (zautoscale) |
|
520 tz = zdat(:); |
|
521 zmin = min (zmin, min (tz)); |
|
522 zmax = max (zmax, max (tz)); |
|
523 zminp = min (zminp, min (tz(tz>0))); |
|
524 endif |
|
525 err = false; |
|
526 if (isvector (xdat) && isvector (ydat) && ismatrix (zdat)) |
|
527 if (rows (zdat) == length (ydat) && columns (zdat) == length (xdat)) |
|
528 [xdat, ydat] = meshgrid (xdat, ydat); |
|
529 else |
|
530 err = true; |
|
531 endif |
|
532 elseif (ismatrix (xdat) && ismatrix (ydat) && ismatrix (zdat)) |
|
533 if (! (size_equal (xdat, ydat) && size_equal (xdat, zdat))) |
|
534 err = true; |
|
535 endif |
|
536 else |
|
537 err = true; |
|
538 endif |
|
539 if (err) |
|
540 error ("__go_draw_axes__: invalid grid data"); |
|
541 endif |
|
542 xlen = columns (zdat); |
|
543 ylen = rows (zdat); |
|
544 if (xlen == columns (xdat) && xlen == columns (ydat) |
|
545 && ylen == rows (xdat) && ylen == rows (ydat)) |
|
546 len = 3 * xlen; |
|
547 zz = zeros (ylen, len); |
|
548 k = 1; |
|
549 for kk = 1:3:len |
|
550 zz(:,kk) = xdat(:,k); |
|
551 zz(:,kk+1) = ydat(:,k); |
|
552 zz(:,kk+2) = zdat(:,k); |
|
553 k++; |
|
554 endfor |
|
555 data{data_idx} = zz; |
|
556 endif |
|
557 usingclause{data_idx} = "using ($1):($2):($3)"; |
|
558 withclause{data_idx} = "with line palette"; |
|
559 |
|
560 fputs (plot_stream, "unset parametric;\n"); |
|
561 fputs (plot_stream, "set hidden3d;\n"); |
|
562 fputs (plot_stream, "set style data lines;\n"); |
|
563 fputs (plot_stream, "set surface;\n"); |
|
564 fputs (plot_stream, "unset contour;\n"); |
|
565 fputs (plot_stream, "set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n"); |
|
566 fputs (plot_stream, "unset colorbox;\n"); |
|
567 |
|
568 case "text" |
|
569 lpos = obj.position; |
|
570 label = obj.string; |
|
571 halign = obj.horizontalalignment; |
|
572 if (nd == 3) |
|
573 fprintf (plot_stream, "set label \"%s\" at %d,%d,%d %s;\n", |
|
574 undo_string_escapes (label), |
|
575 lpos(1), lpos(2), lpos(3), halign); |
|
576 else |
|
577 fprintf (plot_stream, "set label \"%s\" at %d,%d %s;\n", |
|
578 undo_string_escapes (label), |
|
579 lpos(1), lpos(2), halign); |
|
580 endif |
|
581 |
|
582 otherwise |
|
583 error ("__go_draw_axes__: unknown object class, %s", |
|
584 obj.type); |
|
585 endswitch |
|
586 |
|
587 endfor |
|
588 |
|
589 have_data = ! isempty (data); |
|
590 |
|
591 if (xautoscale && have_data) |
|
592 xlim = get_axis_limits (xmin, xmax, xminp, xlogscale); |
|
593 set (h, "xlim", xlim, "xlimmode", "auto"); |
|
594 else |
|
595 xlim = axis_obj.xlim; |
|
596 endif |
|
597 if (strcmp (axis_obj.xdir, "reverse")) |
|
598 xdir = "reverse"; |
|
599 else |
|
600 xdir = "noreverse"; |
|
601 endif |
|
602 fprintf (plot_stream, "set xrange [%g:%g] %s;\n", xlim, xdir); |
|
603 |
|
604 if (yautoscale && have_data) |
|
605 ylim = get_axis_limits (ymin, ymax, yminp, ylogscale); |
|
606 set (h, "ylim", ylim, "ylimmode", "auto"); |
|
607 else |
|
608 ylim = axis_obj.ylim; |
|
609 endif |
|
610 if (strcmp (axis_obj.ydir, "reverse")) |
|
611 ydir = "reverse"; |
|
612 else |
|
613 ydir = "noreverse"; |
|
614 endif |
|
615 fprintf (plot_stream, "set yrange [%g:%g] %s;\n", ylim, ydir); |
|
616 |
|
617 if (nd == 3) |
|
618 if (zautoscale && have_data) |
|
619 zlim = get_axis_limits (zmin, zmax, zminp, zlogscale); |
|
620 set (h, "zlim", zlim, "zlimmode", "auto"); |
|
621 else |
|
622 zlim = axis_obj.zlim; |
|
623 endif |
|
624 if (strcmp (axis_obj.zdir, "reverse")) |
|
625 zdir = "reverse"; |
|
626 else |
|
627 zdir = "noreverse"; |
|
628 endif |
|
629 fprintf (plot_stream, "set zrange [%g:%g] %s;\n", zlim, zdir); |
|
630 endif |
|
631 |
|
632 if (strcmp (axis_obj.box, "on")) |
|
633 if (nd == 3) |
|
634 fputs (plot_stream, "set border 4095;\n"); |
|
635 else |
|
636 fputs (plot_stream, "set border 431;\n"); |
|
637 endif |
|
638 else |
|
639 if (nd == 3) |
|
640 fputs (plot_stream, "set border 895;\n"); |
|
641 else |
|
642 fputs (plot_stream, "set border 3;\n"); |
|
643 fputs (plot_stream, "set xtics nomirror; set ytics nomirror;\n"); |
|
644 endif |
|
645 endif |
|
646 |
|
647 if (strcmp (axis_obj.key, "on")) |
|
648 if (strcmp (axis_obj.keybox, "on")) |
|
649 box = "box"; |
|
650 else |
|
651 box = "nobox"; |
|
652 endif |
|
653 inout = "inside"; |
|
654 switch (axis_obj.keypos) |
|
655 case -1 |
|
656 pos = "right bottom"; |
|
657 inout = "outside"; |
|
658 case 1 |
|
659 pos = "right top"; |
|
660 case 2 |
|
661 pos = "left top"; |
|
662 case 3 |
|
663 pos = "left bottom"; |
|
664 case 4 |
|
665 pos = "right bottom"; |
|
666 otherwise |
|
667 pos = ""; |
|
668 endswitch |
|
669 if (! have_newer_gnuplot) |
|
670 inout = ""; |
|
671 endif |
|
672 fprintf (plot_stream, "set key %s %s %s;\n", inout, pos, box); |
|
673 else |
|
674 fputs (plot_stream, "unset key;\n"); |
|
675 endif |
|
676 |
|
677 fputs (plot_stream, "set style data lines;\n"); |
|
678 |
|
679 if (! use_gnuplot_for_images) |
|
680 for i = 1:ximg_data_idx |
|
681 view_fcn (xlim, ylim, ximg_data{i}, view_zoom, view_cmd); |
|
682 endfor |
|
683 endif |
|
684 |
|
685 if (have_data) |
|
686 |
|
687 if (nd == 2) |
|
688 plot_cmd = "plot"; |
|
689 else |
|
690 plot_cmd = "splot"; |
|
691 rot_x = 90 - axis_obj.view(2); |
|
692 rot_z = axis_obj.view(1); |
|
693 while (rot_z < 0) |
|
694 rot_z += 360; |
|
695 endwhile |
|
696 fprintf (plot_stream, "set view %g, %g;\n", rot_x, rot_z); |
|
697 endif |
|
698 fprintf (plot_stream, "%s \"%s\" %s %s %s", plot_cmd, |
|
699 filespec{1}, usingclause{1}, titlespec{1}, withclause{1}); |
|
700 for i = 2:data_idx |
|
701 fprintf (plot_stream, ", \"%s\" %s %s %s", |
|
702 filespec{i}, usingclause{i}, titlespec{i}, withclause{i}); |
|
703 endfor |
|
704 fputs (plot_stream, ";\n"); |
|
705 for i = 1:data_idx |
|
706 if (strcmp (filespec{i}, "-")) |
|
707 if (nd == 2) |
|
708 fprintf (plot_stream, |
|
709 strcat (repmat ("%g ", 1, rows (data{i})), "\n"), |
|
710 data{i}); |
|
711 else |
|
712 if (parametric(i)) |
|
713 fprintf (plot_stream, "%g %g %g\n", data{i}); |
|
714 else |
|
715 tmp = data{i}; |
|
716 nc = columns (tmp); |
|
717 for j = 1:3:nc |
|
718 fprintf (plot_stream, "%g %g %g\n", tmp(:,j:j+2)'); |
|
719 fputs (plot_stream, "\n"); |
|
720 endfor |
|
721 endif |
|
722 endif |
|
723 fputs (plot_stream, "e\n"); |
|
724 endif |
|
725 endfor |
6431
|
726 else |
|
727 fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n"); |
6405
|
728 endif |
|
729 |
|
730 fflush (plot_stream); |
|
731 |
|
732 else |
|
733 print_usage (); |
|
734 endif |
|
735 |
|
736 endfunction |
|
737 |
|
738 ## Attempt to make "nice" limits from the actual max and min of the |
|
739 ## data. For log plots, we will also use the smallest strictly positive |
|
740 ## value. |
|
741 |
|
742 function lim = get_axis_limits (min_val, max_val, min_pos, logscale) |
|
743 |
|
744 if (logscale) |
|
745 if (isinf (min_pos)) |
|
746 warning ("axis: logscale with no positive values to plot"); |
|
747 endif |
|
748 if (min_val < 0) |
|
749 min_val = min_pos; |
|
750 if (max_val < 0) |
|
751 max_val = min_pos; |
|
752 endif |
|
753 warning ("axis: omitting negative data in log plot"); |
|
754 endif |
|
755 if (min_val == max_val) |
|
756 min_val = 0.9 * min_val; |
|
757 max_val = 1.1 * max_val; |
|
758 endif |
|
759 min_val = 10 ^ floor (log10 (min_val)); |
|
760 max_val = 10 ^ ceil (log10 (max_val)); |
|
761 else |
|
762 if (min_val == 0 && max_val == 0) |
|
763 min_val = -1; |
|
764 max_val = 1; |
|
765 elseif (min_val == max_val) |
|
766 min_val = 0.9 * min_val; |
|
767 max_val = 1.1 * max_val; |
|
768 endif |
|
769 ## FIXME -- to do a better job, we should consider the tic spacing. |
|
770 scale = 10 ^ floor (log10 (max_val - min_val) - 1); |
|
771 min_val = scale * floor (min_val / scale); |
|
772 max_val = scale * ceil (max_val / scale); |
|
773 endif |
|
774 |
|
775 lim = [min_val, max_val]; |
|
776 |
|
777 endfunction |
|
778 |
6425
|
779 function [style, typ] = do_linestyle_command (obj, idx, plot_stream) |
6405
|
780 |
6413
|
781 persistent have_newer_gnuplot ... |
|
782 = compare_versions (__gnuplot_version__ (), "4.0", ">"); |
6405
|
783 |
|
784 if (have_newer_gnuplot) |
|
785 fprintf (plot_stream, "set style line %d default;\n", idx); |
|
786 endif |
|
787 fprintf (plot_stream, "set style line %d", idx); |
|
788 |
|
789 found_style = false; |
6425
|
790 typ = NaN; |
6405
|
791 |
6425
|
792 if (isfield (obj, "color")) |
6405
|
793 color = obj.color; |
|
794 if (isnumeric (color)) |
6425
|
795 if (have_newer_gnuplot) |
|
796 fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", |
|
797 round (255*color)); |
|
798 else |
|
799 if (isequal (color, [0,0,0])) |
|
800 typ = -1; |
|
801 elseif (isequal (color, [1,0,0])) |
|
802 typ = 1; |
|
803 elseif (isequal (color, [0,1,0])) |
|
804 typ = 2; |
|
805 elseif (isequal (color, [0,0,1])) |
|
806 typ = 3; |
|
807 elseif (isequal (color, [1,0,1])) |
|
808 typ = 4; |
|
809 elseif (isequal (color, [0,1,1])) |
|
810 typ = 5; |
|
811 elseif (isequal (color, [1,1,1])) |
|
812 typ = 6; |
|
813 elseif (isequal (color, [1,1,0])) |
|
814 typ = 7; |
|
815 else |
|
816 typ = 2; |
|
817 endif |
|
818 endif |
6405
|
819 endif |
|
820 found_style = true; |
|
821 endif |
|
822 |
|
823 if (isfield (obj, "linestyle")) |
|
824 switch (obj.linestyle) |
|
825 case "-" |
6415
|
826 lt = "1"; |
6405
|
827 case "--" |
6415
|
828 lt = "2"; |
6405
|
829 case ":" |
6415
|
830 lt = "3"; |
6405
|
831 case "-." |
6415
|
832 lt = "6"; |
6405
|
833 case "none" |
|
834 lt = ""; |
|
835 otherwise |
|
836 lt = ""; |
|
837 endswitch |
6415
|
838 if (! isempty (lt)) |
|
839 fprintf (plot_stream, " linetype %s", lt); |
|
840 found_style = true; |
|
841 endif |
6405
|
842 else |
|
843 lt = ""; |
|
844 endif |
|
845 |
|
846 if (isfield (obj, "linewidth")) |
|
847 fprintf (plot_stream, " linewidth %f", obj.linewidth); |
|
848 found_style = true; |
|
849 endif |
|
850 |
|
851 if (isfield (obj, "marker")) |
|
852 switch (obj.marker) |
|
853 case "+" |
|
854 pt = "1"; |
|
855 case "o" |
6413
|
856 pt = "6"; |
6405
|
857 case "*" |
|
858 pt = "3"; |
|
859 case "." |
6413
|
860 pt = "7"; |
6405
|
861 case "x" |
|
862 pt = "2"; |
|
863 case {"square", "s"} |
|
864 pt = "5"; |
|
865 case {"diamond", "d"} |
|
866 pt = "13"; |
|
867 case "^" |
|
868 pt = "9"; |
|
869 case "v" |
|
870 pt = "11"; |
|
871 case ">" |
|
872 pt = "8"; |
|
873 case "<" |
|
874 pt = "10"; |
|
875 case {"pentagram", "p"} |
|
876 pt = "4"; |
|
877 case {"hexagram", "h"} |
6413
|
878 pt = "12"; |
6405
|
879 case "none" |
|
880 pt = ""; |
|
881 otherwise |
|
882 pt = ""; |
|
883 endswitch |
|
884 if (! isempty (pt)) |
|
885 fprintf (plot_stream, " pointtype %s", pt); |
|
886 found_style = true; |
|
887 endif |
|
888 else |
|
889 pt = ""; |
|
890 endif |
|
891 |
|
892 if (isfield (obj, "markersize")) |
|
893 fprintf (plot_stream, " pointsize %f", obj.markersize); |
|
894 found_style = true; |
|
895 endif |
|
896 |
|
897 style = "lines"; |
|
898 if (isempty (lt)) |
|
899 if (! isempty (pt)) |
|
900 style = "points"; |
|
901 endif |
|
902 elseif (! isempty (pt)) |
|
903 style = "linespoints"; |
|
904 endif |
|
905 |
|
906 if (have_newer_gnuplot && ! found_style) |
|
907 fputs (plot_stream, " default"); |
|
908 endif |
|
909 |
|
910 fputs (plot_stream, ";\n"); |
|
911 |
|
912 endfunction |