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} = ""; |
|
338 usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using %s", |
|
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++; |
|
352 filespec{data_idx} = '-'; |
|
353 if (isempty (obj.keylabel)) |
|
354 titlespec{data_idx} = "title \"\""; |
|
355 else |
|
356 titlespec{data_idx} = strcat ("title \"", obj.keylabel, "\""); |
|
357 endif |
|
358 style = do_linestyle_command (obj, data_idx, plot_stream); |
|
359 usingclause{data_idx} = ""; |
|
360 withclause{data_idx} = sprintf ("with %s linestyle %d", |
|
361 style, data_idx); |
|
362 parametric(i) = true; |
|
363 if (! isempty (obj.zdata)) |
|
364 nd = 3; |
|
365 xdat = obj.xdata(:); |
|
366 ydat = obj.ydata(:); |
|
367 zdat = obj.zdata(:); |
|
368 if (xautoscale) |
|
369 xmin = min (xmin, min (xdat)); |
|
370 xmax = max (xmax, max (xdat)); |
|
371 xminp = min (xminp, min (xdat(xdat>0))); |
|
372 endif |
|
373 if (yautoscale) |
|
374 ymin = min (ymin, min (ydat)); |
|
375 ymax = max (ymax, max (ydat)); |
|
376 yminp = min (yminp, min (ydat(ydat>0))); |
|
377 endif |
|
378 if (zautoscale) |
|
379 zmin = min (zmin, min (zdat)); |
|
380 zmax = max (zmax, max (zdat)); |
|
381 zminp = min (zminp, min (zdat(zdat>0))); |
|
382 endif |
|
383 data{data_idx} = [xdat, ydat, zdat]'; |
|
384 usingclause{data_idx} = "using ($1):($2):($3)"; |
|
385 fputs (plot_stream, "set parametric;\n"); |
|
386 fputs (plot_stream, "unset hidden3d;\n"); |
|
387 fputs (plot_stream, "set style data lines;\n"); |
|
388 fputs (plot_stream, "set surface;\n"); |
|
389 fputs (plot_stream, "unset contour;\n"); |
|
390 else |
|
391 nd = 2; |
|
392 xdat = obj.xdata(:); |
|
393 ydat = obj.ydata(:); |
|
394 ldat = obj.ldata; |
|
395 yerr = xerr = false; |
|
396 if (! isempty (ldat)) |
|
397 yerr = true; |
|
398 ldat = ldat(:); |
|
399 endif |
|
400 udat = obj.udata; |
|
401 if (! isempty (udat)) |
|
402 udat = udat(:); |
|
403 endif |
|
404 xldat = obj.xldata; |
|
405 if (! isempty (xldat)) |
|
406 xerr = true; |
|
407 xldat = xldat(:); |
|
408 endif |
|
409 xudat = obj.xudata; |
|
410 if (! isempty (xudat)) |
|
411 xudat = xudat(:); |
|
412 endif |
|
413 if (yerr) |
|
414 ylo = ydat-ldat; |
|
415 yhi = ydat+udat; |
|
416 if (yautoscale) |
|
417 ty = [ydat; ylo; yhi]; |
|
418 ymin = min (ymin, min (ty)); |
|
419 ymax = max (ymax, max (ty)); |
|
420 yminp = min (yminp, min (ty(ty>0))); |
|
421 endif |
|
422 if (xerr) |
|
423 xlo = xdat-xldat; |
|
424 xhi = xdat+xudat; |
|
425 if (xautoscale) |
|
426 tx = [xdat; xlo; xhi]; |
|
427 xmin = min (xmin, min (tx)); |
|
428 xmax = max (xmax, max (tx)); |
|
429 xminp = min (xminp, min (tx(tx>0))); |
|
430 endif |
|
431 data{data_idx} = [xdat, ydat, xlo, xhi, ylo, yhi]'; |
|
432 usingclause{data_idx} = "using ($1):($2):($3):($4):($5):($6)"; |
|
433 withclause{data_idx} = sprintf ("with xyerrorbars linestyle %d", |
|
434 data_idx); |
|
435 else |
|
436 if (xautoscale) |
|
437 xmin = min (xmin, min (xdat)); |
|
438 xmax = max (xmax, max (xdat)); |
|
439 xminp = min (xminp, min (tx(tx>0))); |
|
440 endif |
|
441 data{data_idx} = [xdat, ydat, ylo, yhi]'; |
|
442 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
|
443 withclause{data_idx} = sprintf ("with yerrorbars linestyle %d", |
|
444 data_idx); |
|
445 endif |
|
446 elseif (xerr) |
|
447 xlo = xdat-xldat; |
|
448 xhi = xdat+xudat; |
|
449 if (xautoscale) |
|
450 tx = [xdat; xlo; xhi]; |
|
451 xmin = min (xmin, min (tx)); |
|
452 xmax = max (xmax, max (tx)); |
|
453 xminp = min (xminp, min (tx(tx>0))); |
|
454 endif |
|
455 if (yautoscale) |
|
456 ymin = min (ymin, min (ydat)); |
|
457 ymax = max (ymax, max (ydat)); |
|
458 yminp = min (yminp, min (ty(ty>0))); |
|
459 endif |
|
460 data{data_idx} = [xdat, ydat, xlo, xhi]'; |
|
461 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
|
462 withclause{data_idx} = sprintf ("with xerrorbars linestyle %d", |
|
463 data_idx); |
|
464 else |
|
465 if (xautoscale) |
|
466 xmin = min (xmin, min (xdat)); |
|
467 xmax = max (xmax, max (xdat)); |
|
468 xminp = min (xminp, min (xdat(xdat>0))); |
|
469 endif |
|
470 if (yautoscale) |
|
471 ymin = min (ymin, min (ydat)); |
|
472 ymax = max (ymax, max (ydat)); |
|
473 yminp = min (yminp, min (ydat(ydat>0))); |
|
474 endif |
|
475 data{data_idx} = [xdat, ydat]'; |
|
476 usingclause{data_idx} = "using ($1):($2)"; |
|
477 endif |
|
478 endif |
|
479 |
|
480 case "surface" |
|
481 data_idx++; |
|
482 style = do_linestyle_command (obj, data_idx, plot_stream); |
|
483 filespec{data_idx} = '-'; |
|
484 if (isempty (obj.keylabel)) |
|
485 titlespec{data_idx} = "title \"\""; |
|
486 else |
|
487 titlespec{data_idx} = strcat ("title \"", obj.keylabel, "\""); |
|
488 endif |
|
489 usingclause{data_idx} = ""; |
|
490 withclause{data_idx} = sprintf ("with %s linestyle %d", |
|
491 style, data_idx); |
|
492 parametric(i) = false; |
|
493 nd = 3; |
|
494 xdat = obj.xdata; |
|
495 ydat = obj.ydata; |
|
496 zdat = obj.zdata; |
|
497 if (xautoscale) |
|
498 tx = xdat(:); |
|
499 xmin = min (xmin, min (tx)); |
|
500 xmax = max (xmax, max (tx)); |
|
501 xminp = min (xminp, min (tx(tx>0))); |
|
502 endif |
|
503 if (yautoscale) |
|
504 ty = ydat(:); |
|
505 ymin = min (ymin, min (ty)); |
|
506 ymax = max (ymax, max (ty)); |
|
507 yminp = min (yminp, min (ty(ty>0))); |
|
508 endif |
|
509 if (zautoscale) |
|
510 tz = zdat(:); |
|
511 zmin = min (zmin, min (tz)); |
|
512 zmax = max (zmax, max (tz)); |
|
513 zminp = min (zminp, min (tz(tz>0))); |
|
514 endif |
|
515 err = false; |
|
516 if (isvector (xdat) && isvector (ydat) && ismatrix (zdat)) |
|
517 if (rows (zdat) == length (ydat) && columns (zdat) == length (xdat)) |
|
518 [xdat, ydat] = meshgrid (xdat, ydat); |
|
519 else |
|
520 err = true; |
|
521 endif |
|
522 elseif (ismatrix (xdat) && ismatrix (ydat) && ismatrix (zdat)) |
|
523 if (! (size_equal (xdat, ydat) && size_equal (xdat, zdat))) |
|
524 err = true; |
|
525 endif |
|
526 else |
|
527 err = true; |
|
528 endif |
|
529 if (err) |
|
530 error ("__go_draw_axes__: invalid grid data"); |
|
531 endif |
|
532 xlen = columns (zdat); |
|
533 ylen = rows (zdat); |
|
534 if (xlen == columns (xdat) && xlen == columns (ydat) |
|
535 && ylen == rows (xdat) && ylen == rows (ydat)) |
|
536 len = 3 * xlen; |
|
537 zz = zeros (ylen, len); |
|
538 k = 1; |
|
539 for kk = 1:3:len |
|
540 zz(:,kk) = xdat(:,k); |
|
541 zz(:,kk+1) = ydat(:,k); |
|
542 zz(:,kk+2) = zdat(:,k); |
|
543 k++; |
|
544 endfor |
|
545 data{data_idx} = zz; |
|
546 endif |
|
547 usingclause{data_idx} = "using ($1):($2):($3)"; |
|
548 withclause{data_idx} = "with line palette"; |
|
549 |
|
550 fputs (plot_stream, "unset parametric;\n"); |
|
551 fputs (plot_stream, "set hidden3d;\n"); |
|
552 fputs (plot_stream, "set style data lines;\n"); |
|
553 fputs (plot_stream, "set surface;\n"); |
|
554 fputs (plot_stream, "unset contour;\n"); |
|
555 fputs (plot_stream, "set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n"); |
|
556 fputs (plot_stream, "unset colorbox;\n"); |
|
557 |
|
558 case "text" |
|
559 lpos = obj.position; |
|
560 label = obj.string; |
|
561 halign = obj.horizontalalignment; |
|
562 if (nd == 3) |
|
563 fprintf (plot_stream, "set label \"%s\" at %d,%d,%d %s;\n", |
|
564 undo_string_escapes (label), |
|
565 lpos(1), lpos(2), lpos(3), halign); |
|
566 else |
|
567 fprintf (plot_stream, "set label \"%s\" at %d,%d %s;\n", |
|
568 undo_string_escapes (label), |
|
569 lpos(1), lpos(2), halign); |
|
570 endif |
|
571 |
|
572 otherwise |
|
573 error ("__go_draw_axes__: unknown object class, %s", |
|
574 obj.type); |
|
575 endswitch |
|
576 |
|
577 endfor |
|
578 |
|
579 have_data = ! isempty (data); |
|
580 |
|
581 if (xautoscale && have_data) |
|
582 xlim = get_axis_limits (xmin, xmax, xminp, xlogscale); |
|
583 set (h, "xlim", xlim, "xlimmode", "auto"); |
|
584 else |
|
585 xlim = axis_obj.xlim; |
|
586 endif |
|
587 if (strcmp (axis_obj.xdir, "reverse")) |
|
588 xdir = "reverse"; |
|
589 else |
|
590 xdir = "noreverse"; |
|
591 endif |
|
592 fprintf (plot_stream, "set xrange [%g:%g] %s;\n", xlim, xdir); |
|
593 |
|
594 if (yautoscale && have_data) |
|
595 ylim = get_axis_limits (ymin, ymax, yminp, ylogscale); |
|
596 set (h, "ylim", ylim, "ylimmode", "auto"); |
|
597 else |
|
598 ylim = axis_obj.ylim; |
|
599 endif |
|
600 if (strcmp (axis_obj.ydir, "reverse")) |
|
601 ydir = "reverse"; |
|
602 else |
|
603 ydir = "noreverse"; |
|
604 endif |
|
605 fprintf (plot_stream, "set yrange [%g:%g] %s;\n", ylim, ydir); |
|
606 |
|
607 if (nd == 3) |
|
608 if (zautoscale && have_data) |
|
609 zlim = get_axis_limits (zmin, zmax, zminp, zlogscale); |
|
610 set (h, "zlim", zlim, "zlimmode", "auto"); |
|
611 else |
|
612 zlim = axis_obj.zlim; |
|
613 endif |
|
614 if (strcmp (axis_obj.zdir, "reverse")) |
|
615 zdir = "reverse"; |
|
616 else |
|
617 zdir = "noreverse"; |
|
618 endif |
|
619 fprintf (plot_stream, "set zrange [%g:%g] %s;\n", zlim, zdir); |
|
620 endif |
|
621 |
|
622 if (strcmp (axis_obj.box, "on")) |
|
623 if (nd == 3) |
|
624 fputs (plot_stream, "set border 4095;\n"); |
|
625 else |
|
626 fputs (plot_stream, "set border 431;\n"); |
|
627 endif |
|
628 else |
|
629 if (nd == 3) |
|
630 fputs (plot_stream, "set border 895;\n"); |
|
631 else |
|
632 fputs (plot_stream, "set border 3;\n"); |
|
633 fputs (plot_stream, "set xtics nomirror; set ytics nomirror;\n"); |
|
634 endif |
|
635 endif |
|
636 |
|
637 if (strcmp (axis_obj.key, "on")) |
|
638 if (strcmp (axis_obj.keybox, "on")) |
|
639 box = "box"; |
|
640 else |
|
641 box = "nobox"; |
|
642 endif |
|
643 inout = "inside"; |
|
644 switch (axis_obj.keypos) |
|
645 case -1 |
|
646 pos = "right bottom"; |
|
647 inout = "outside"; |
|
648 case 1 |
|
649 pos = "right top"; |
|
650 case 2 |
|
651 pos = "left top"; |
|
652 case 3 |
|
653 pos = "left bottom"; |
|
654 case 4 |
|
655 pos = "right bottom"; |
|
656 otherwise |
|
657 pos = ""; |
|
658 endswitch |
|
659 if (! have_newer_gnuplot) |
|
660 inout = ""; |
|
661 endif |
|
662 fprintf (plot_stream, "set key %s %s %s;\n", inout, pos, box); |
|
663 else |
|
664 fputs (plot_stream, "unset key;\n"); |
|
665 endif |
|
666 |
|
667 fputs (plot_stream, "set style data lines;\n"); |
|
668 |
|
669 if (! use_gnuplot_for_images) |
|
670 for i = 1:ximg_data_idx |
|
671 view_fcn (xlim, ylim, ximg_data{i}, view_zoom, view_cmd); |
|
672 endfor |
|
673 endif |
|
674 |
|
675 if (have_data) |
|
676 |
|
677 if (nd == 2) |
|
678 plot_cmd = "plot"; |
|
679 else |
|
680 plot_cmd = "splot"; |
|
681 rot_x = 90 - axis_obj.view(2); |
|
682 rot_z = axis_obj.view(1); |
|
683 while (rot_z < 0) |
|
684 rot_z += 360; |
|
685 endwhile |
|
686 fprintf (plot_stream, "set view %g, %g;\n", rot_x, rot_z); |
|
687 endif |
|
688 fprintf (plot_stream, "%s \"%s\" %s %s %s", plot_cmd, |
|
689 filespec{1}, usingclause{1}, titlespec{1}, withclause{1}); |
|
690 for i = 2:data_idx |
|
691 fprintf (plot_stream, ", \"%s\" %s %s %s", |
|
692 filespec{i}, usingclause{i}, titlespec{i}, withclause{i}); |
|
693 endfor |
|
694 fputs (plot_stream, ";\n"); |
|
695 for i = 1:data_idx |
|
696 if (strcmp (filespec{i}, "-")) |
|
697 if (nd == 2) |
|
698 fprintf (plot_stream, |
|
699 strcat (repmat ("%g ", 1, rows (data{i})), "\n"), |
|
700 data{i}); |
|
701 else |
|
702 if (parametric(i)) |
|
703 fprintf (plot_stream, "%g %g %g\n", data{i}); |
|
704 else |
|
705 tmp = data{i}; |
|
706 nc = columns (tmp); |
|
707 for j = 1:3:nc |
|
708 fprintf (plot_stream, "%g %g %g\n", tmp(:,j:j+2)'); |
|
709 fputs (plot_stream, "\n"); |
|
710 endfor |
|
711 endif |
|
712 endif |
|
713 fputs (plot_stream, "e\n"); |
|
714 endif |
|
715 endfor |
|
716 endif |
|
717 |
|
718 fflush (plot_stream); |
|
719 |
|
720 else |
|
721 print_usage (); |
|
722 endif |
|
723 |
|
724 endfunction |
|
725 |
|
726 ## Attempt to make "nice" limits from the actual max and min of the |
|
727 ## data. For log plots, we will also use the smallest strictly positive |
|
728 ## value. |
|
729 |
|
730 function lim = get_axis_limits (min_val, max_val, min_pos, logscale) |
|
731 |
|
732 if (logscale) |
|
733 if (isinf (min_pos)) |
|
734 warning ("axis: logscale with no positive values to plot"); |
|
735 endif |
|
736 if (min_val < 0) |
|
737 min_val = min_pos; |
|
738 if (max_val < 0) |
|
739 max_val = min_pos; |
|
740 endif |
|
741 warning ("axis: omitting negative data in log plot"); |
|
742 endif |
|
743 if (min_val == max_val) |
|
744 min_val = 0.9 * min_val; |
|
745 max_val = 1.1 * max_val; |
|
746 endif |
|
747 min_val = 10 ^ floor (log10 (min_val)); |
|
748 max_val = 10 ^ ceil (log10 (max_val)); |
|
749 else |
|
750 if (min_val == 0 && max_val == 0) |
|
751 min_val = -1; |
|
752 max_val = 1; |
|
753 elseif (min_val == max_val) |
|
754 min_val = 0.9 * min_val; |
|
755 max_val = 1.1 * max_val; |
|
756 endif |
|
757 ## FIXME -- to do a better job, we should consider the tic spacing. |
|
758 scale = 10 ^ floor (log10 (max_val - min_val) - 1); |
|
759 min_val = scale * floor (min_val / scale); |
|
760 max_val = scale * ceil (max_val / scale); |
|
761 endif |
|
762 |
|
763 lim = [min_val, max_val]; |
|
764 |
|
765 endfunction |
|
766 |
|
767 function style = do_linestyle_command (obj, idx, plot_stream) |
|
768 |
6413
|
769 persistent have_newer_gnuplot ... |
|
770 = compare_versions (__gnuplot_version__ (), "4.0", ">"); |
6405
|
771 |
|
772 if (have_newer_gnuplot) |
|
773 fprintf (plot_stream, "set style line %d default;\n", idx); |
|
774 endif |
|
775 fprintf (plot_stream, "set style line %d", idx); |
|
776 |
|
777 found_style = false; |
|
778 |
|
779 if (isfield (obj, "color") && have_newer_gnuplot) |
|
780 color = obj.color; |
|
781 if (isnumeric (color)) |
|
782 fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", |
|
783 round (255*color)); |
|
784 endif |
|
785 found_style = true; |
|
786 endif |
|
787 |
|
788 if (isfield (obj, "linestyle")) |
|
789 switch (obj.linestyle) |
|
790 case "-" |
6415
|
791 lt = "1"; |
6405
|
792 case "--" |
6415
|
793 lt = "2"; |
6405
|
794 case ":" |
6415
|
795 lt = "3"; |
6405
|
796 case "-." |
6415
|
797 lt = "6"; |
6405
|
798 case "none" |
|
799 lt = ""; |
|
800 otherwise |
|
801 lt = ""; |
|
802 endswitch |
6415
|
803 if (! isempty (lt)) |
|
804 fprintf (plot_stream, " linetype %s", lt); |
|
805 found_style = true; |
|
806 endif |
6405
|
807 else |
|
808 lt = ""; |
|
809 endif |
|
810 |
|
811 if (isfield (obj, "linewidth")) |
|
812 fprintf (plot_stream, " linewidth %f", obj.linewidth); |
|
813 found_style = true; |
|
814 endif |
|
815 |
|
816 if (isfield (obj, "marker")) |
|
817 switch (obj.marker) |
|
818 case "+" |
|
819 pt = "1"; |
|
820 case "o" |
6413
|
821 pt = "6"; |
6405
|
822 case "*" |
|
823 pt = "3"; |
|
824 case "." |
6413
|
825 pt = "7"; |
6405
|
826 case "x" |
|
827 pt = "2"; |
|
828 case {"square", "s"} |
|
829 pt = "5"; |
|
830 case {"diamond", "d"} |
|
831 pt = "13"; |
|
832 case "^" |
|
833 pt = "9"; |
|
834 case "v" |
|
835 pt = "11"; |
|
836 case ">" |
|
837 pt = "8"; |
|
838 case "<" |
|
839 pt = "10"; |
|
840 case {"pentagram", "p"} |
|
841 pt = "4"; |
|
842 case {"hexagram", "h"} |
6413
|
843 pt = "12"; |
6405
|
844 case "none" |
|
845 pt = ""; |
|
846 otherwise |
|
847 pt = ""; |
|
848 endswitch |
|
849 if (! isempty (pt)) |
|
850 fprintf (plot_stream, " pointtype %s", pt); |
|
851 found_style = true; |
|
852 endif |
|
853 else |
|
854 pt = ""; |
|
855 endif |
|
856 |
|
857 if (isfield (obj, "markersize")) |
|
858 fprintf (plot_stream, " pointsize %f", obj.markersize); |
|
859 found_style = true; |
|
860 endif |
|
861 |
|
862 style = "lines"; |
|
863 if (isempty (lt)) |
|
864 if (! isempty (pt)) |
|
865 style = "points"; |
|
866 endif |
|
867 elseif (! isempty (pt)) |
|
868 style = "linespoints"; |
|
869 endif |
|
870 |
|
871 if (have_newer_gnuplot && ! found_style) |
|
872 fputs (plot_stream, " default"); |
|
873 endif |
|
874 |
|
875 fputs (plot_stream, ";\n"); |
|
876 |
|
877 endfunction |