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 |
|
23 function __go_draw_axes__ (h, plot_stream) |
|
24 |
|
25 if (nargin == 2) |
|
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? |
|
35 |
|
36 if (! isempty (axis_obj.outerposition)) |
|
37 pos = axis_obj.outerposition; |
6914
|
38 fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2)); |
|
39 fprintf (plot_stream, "set size %.15g, %.15g;\n", pos(3), pos(4)); |
6405
|
40 endif |
|
41 |
|
42 if (! isempty (axis_obj.position)) |
|
43 pos = axis_obj.position; |
6914
|
44 fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2)); |
|
45 fprintf (plot_stream, "set size %.15g, %.15g;\n", pos(3), pos(4)); |
6405
|
46 endif |
|
47 |
6758
|
48 if (strcmpi (axis_obj.dataaspectratiomode, "manual")) |
6405
|
49 r = axis_obj.dataaspectratio; |
6914
|
50 fprintf (plot_stream, "set size ratio %.15g;\n", -r(2)/r(1)); |
6405
|
51 else |
|
52 fputs (plot_stream, "set size noratio;\n"); |
|
53 endif |
|
54 |
6778
|
55 fputs (plot_stream, "unset label;\n"); |
|
56 |
6405
|
57 if (! isempty (axis_obj.title)) |
|
58 t = get (axis_obj.title); |
|
59 if (isempty (t.string)) |
|
60 fputs (plot_stream, "unset title;\n"); |
|
61 else |
|
62 fprintf (plot_stream, "set title \"%s\";\n", |
|
63 undo_string_escapes (t.string)); |
|
64 endif |
|
65 endif |
|
66 |
|
67 if (! isempty (axis_obj.xlabel)) |
|
68 t = get (axis_obj.xlabel); |
6737
|
69 angle = t.rotation; |
6405
|
70 if (isempty (t.string)) |
|
71 fputs (plot_stream, "unset xlabel;\n"); |
|
72 else |
6738
|
73 fprintf (plot_stream, "set xlabel \"%s\"", |
|
74 undo_string_escapes (t.string)); |
|
75 if (have_newer_gnuplot) |
|
76 ## Rotation of xlabel not yet support by gnuplot as of 4.2, but |
|
77 ## there is no message about it. |
|
78 fprintf (plot_stream, " rotate by %f", angle); |
|
79 endif |
|
80 fputs (plot_stream, ";\n"); |
6405
|
81 endif |
|
82 endif |
|
83 |
|
84 if (! isempty (axis_obj.ylabel)) |
|
85 t = get (axis_obj.ylabel); |
6737
|
86 angle = t.rotation; |
6405
|
87 if (isempty (t.string)) |
|
88 fputs (plot_stream, "unset ylabel;\n"); |
|
89 else |
6738
|
90 fprintf (plot_stream, "set ylabel \"%s\"", |
|
91 undo_string_escapes (t.string)); |
|
92 if (have_newer_gnuplot) |
6766
|
93 fprintf (plot_stream, " rotate by %f;\n", angle); |
6738
|
94 endif |
|
95 fputs (plot_stream, ";\n"); |
6405
|
96 endif |
|
97 endif |
|
98 |
|
99 if (! isempty (axis_obj.zlabel)) |
|
100 t = get (axis_obj.zlabel); |
6737
|
101 angle = t.rotation; |
6405
|
102 if (isempty (t.string)) |
|
103 fputs (plot_stream, "unset zlabel;\n"); |
|
104 else |
6738
|
105 fprintf (plot_stream, "set zlabel \"%s\"", |
|
106 undo_string_escapes (t.string)); |
|
107 if (have_newer_gnuplot) |
|
108 ## Rotation of zlabel not yet support by gnuplot as of 4.2, but |
|
109 ## there is no message about it. |
|
110 fprintf (plot_stream, " rotate by %f;\n", angle); |
|
111 endif |
|
112 fputs (plot_stream, ";\n"); |
6405
|
113 endif |
|
114 endif |
|
115 |
6809
|
116 if (strcmpi (axis_obj.xaxislocation, "top")) |
|
117 xaxisloc = "x2"; |
|
118 xaxisloc_using = "x2"; |
|
119 else |
|
120 xaxisloc = "x"; |
|
121 xaxisloc_using = "x1"; |
|
122 endif |
|
123 if (strcmpi (axis_obj.yaxislocation, "right")) |
|
124 yaxisloc = "y2"; |
|
125 yaxisloc_using = "y2"; |
|
126 else |
|
127 yaxisloc = "y"; |
|
128 yaxisloc_using = "y1"; |
|
129 endif |
|
130 |
6758
|
131 if (strcmpi (axis_obj.xgrid, "on")) |
6809
|
132 fprintf (plot_stream, "set grid %stics;\n", xaxisloc); |
6405
|
133 else |
6809
|
134 fprintf (plot_stream, "set grid no%stics;\n", xaxisloc); |
6405
|
135 endif |
|
136 |
6758
|
137 if (strcmpi (axis_obj.ygrid, "on")) |
6809
|
138 fprintf (plot_stream, "set grid %stics;\n", yaxisloc); |
6405
|
139 else |
6809
|
140 fprintf (plot_stream, "set grid no%stics;\n", yaxisloc); |
6405
|
141 endif |
|
142 |
6758
|
143 if (strcmpi (axis_obj.zgrid, "on")) |
6405
|
144 fputs (plot_stream, "set grid ztics;\n"); |
|
145 else |
7085
|
146 fputs (plot_stream, "set grid noztics;\n"); |
6405
|
147 endif |
|
148 |
6758
|
149 if (strcmpi (axis_obj.xminorgrid, "on")) |
6809
|
150 fprintf (plot_stream, "set m%stics 5;\n", xaxisloc); |
|
151 fprintf (plot_stream, "set grid m%stics;\n", xaxisloc); |
6405
|
152 else |
6809
|
153 fprintf (plot_stream, "set grid nom%stics;\n", xaxisloc); |
6405
|
154 endif |
|
155 |
6758
|
156 if (strcmpi (axis_obj.yminorgrid, "on")) |
6809
|
157 fprintf (plot_stream, "set m%stics 5;\n", yaxisloc); |
|
158 fprintf (plot_stream, "set grid m%stics;\n", yaxisloc); |
6405
|
159 else |
6809
|
160 fprintf (plot_stream, "set grid nom%stics;\n", yaxisloc); |
6405
|
161 endif |
|
162 |
6758
|
163 if (strcmpi (axis_obj.zminorgrid, "on")) |
6405
|
164 fputs (plot_stream, "set mztics 5;\n"); |
|
165 fputs (plot_stream, "set grid mztics;\n"); |
|
166 else |
|
167 fputs (plot_stream, "set grid nomztics;\n"); |
|
168 endif |
|
169 |
6745
|
170 do_tics (axis_obj, plot_stream); |
6405
|
171 |
6758
|
172 xlogscale = strcmpi (axis_obj.xscale, "log"); |
6405
|
173 if (xlogscale) |
6809
|
174 fprintf (plot_stream, "set logscale %s;\n", xaxisloc); |
6405
|
175 else |
6809
|
176 fprintf (plot_stream, "unset logscale %s;\n", xaxisloc); |
6405
|
177 endif |
|
178 |
6758
|
179 ylogscale = strcmpi (axis_obj.yscale, "log"); |
6405
|
180 if (ylogscale) |
6809
|
181 fprintf (plot_stream, "set logscale %s;\n", yaxisloc); |
6405
|
182 else |
6809
|
183 fprintf (plot_stream, "unset logscale %s;\n", yaxisloc); |
6405
|
184 endif |
|
185 |
6758
|
186 zlogscale = strcmpi (axis_obj.zscale, "log"); |
6405
|
187 if (zlogscale) |
|
188 fputs (plot_stream, "set logscale z;\n"); |
|
189 else |
|
190 fputs (plot_stream, "unset logscale z;\n"); |
|
191 endif |
|
192 |
6758
|
193 xautoscale = strcmpi (axis_obj.xlimmode, "auto"); |
|
194 yautoscale = strcmpi (axis_obj.ylimmode, "auto"); |
|
195 zautoscale = strcmpi (axis_obj.zlimmode, "auto"); |
6405
|
196 |
|
197 kids = axis_obj.children; |
|
198 |
|
199 nd = 0; |
|
200 data_idx = 0; |
|
201 data = cell (); |
6464
|
202 is_image_data = []; |
6405
|
203 |
7012
|
204 xminp = yminp = zminp = Inf; |
|
205 xmax = ymax = zmax = -Inf; |
|
206 xmin = ymin = zmin = Inf; |
6405
|
207 |
|
208 [view_cmd, view_fcn, view_zoom] = image_viewer (); |
|
209 use_gnuplot_for_images = (ischar (view_fcn) |
|
210 && strcmp (view_fcn, "gnuplot_internal")); |
|
211 |
|
212 ximg_data = {}; |
|
213 ximg_data_idx = 0; |
|
214 |
|
215 for i = 1:length (kids) |
|
216 |
|
217 obj = get (kids(i)); |
|
218 |
|
219 switch (obj.type) |
|
220 case "image" |
|
221 ## FIXME - Is there a better way to determine if the plot |
|
222 ## command should be "plot" or "splot"????? Could have images |
|
223 ## projected into 3D so there is really no reason to limit |
|
224 ## this. |
|
225 if (nd == 0) |
|
226 nd = 2; |
|
227 endif |
|
228 |
|
229 img_data = obj.cdata; |
|
230 img_colormap = parent_figure_obj.colormap; |
|
231 img_xdata = obj.xdata; |
|
232 img_ydata = obj.ydata; |
|
233 |
|
234 if (use_gnuplot_for_images) |
|
235 |
|
236 data_idx++; |
6464
|
237 is_image_data(data_idx) = true; |
6861
|
238 parametric(data_idx) = false; |
6405
|
239 |
|
240 [y_dim, x_dim] = size (img_data(:,:,1)); |
|
241 if (x_dim > 1) |
|
242 dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1); |
|
243 else |
|
244 dx = 1; |
|
245 endif |
|
246 if (y_dim > 1) |
|
247 dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1); |
|
248 else |
|
249 dy = 1; |
|
250 endif |
|
251 x_origin = min (img_xdata); |
|
252 y_origin = min (img_ydata); |
|
253 |
|
254 if (nd == 2) |
|
255 if (xautoscale) |
|
256 xmin = min (xmin, min (img_xdata) - dx/2); |
|
257 xmax = max (xmax, max (img_xdata) + dx/2); |
|
258 xminp = min (xminp, min (img_xdata((img_xdata - dx/2)>0)) - dx/2); |
|
259 endif |
|
260 if (yautoscale) |
|
261 ymin = min (ymin, min (img_ydata) - dy/2); |
|
262 ymax = max (ymax, max (img_ydata) + dy/2); |
|
263 yminp = min (yminp, min (img_ydata((img_ydata - dy/2)>0)) - dy/2); |
|
264 endif |
|
265 else |
|
266 ## Can have images in 3D, but the image routines don't seem |
|
267 ## to have a means of arbitrary projection. |
|
268 endif |
|
269 |
|
270 if (ndims (img_data) == 3) |
6464
|
271 data{data_idx} = permute (img_data, [3, 1, 2])(:); |
6405
|
272 format = "1:2:3"; |
|
273 imagetype = "rgbimage"; |
|
274 else |
6464
|
275 data{data_idx} = img_data(:); |
6405
|
276 format = "1"; |
|
277 imagetype = "image"; |
6464
|
278 |
|
279 palette_size = rows (img_colormap); |
|
280 fprintf (plot_stream, |
|
281 "set palette positive color model RGB maxcolors %i;\n", |
|
282 palette_size); |
|
283 fprintf (plot_stream, |
|
284 "set palette file \"-\" binary record=%d using 1:2:3:4;\n", |
|
285 palette_size); |
|
286 fwrite (plot_stream, [1:palette_size; img_colormap'], "float32"); |
6405
|
287 endif |
|
288 |
6579
|
289 titlespec{data_idx} = "title \"\""; |
6914
|
290 usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx origin=(%.15g,%.15g) dx=%.15g dy=%.15g using %s", |
6405
|
291 x_dim, y_dim, x_origin, y_origin, dx, dy, format); |
|
292 withclause{data_idx} = sprintf ("with %s", imagetype); |
|
293 |
|
294 else |
|
295 ximg_data{++ximg_data_idx} = img_data; |
|
296 endif |
|
297 |
|
298 case "line" |
|
299 data_idx++; |
6464
|
300 is_image_data(data_idx) = false; |
6861
|
301 parametric(data_idx) = true; |
6405
|
302 if (isempty (obj.keylabel)) |
|
303 titlespec{data_idx} = "title \"\""; |
|
304 else |
7094
|
305 tmp = undo_string_escapes (obj.keylabel); |
|
306 titlespec{data_idx} = strcat ("title \"", tmp, "\""); |
6405
|
307 endif |
6465
|
308 [style, typ, with] = do_linestyle_command (obj, data_idx, plot_stream); |
6405
|
309 usingclause{data_idx} = ""; |
6425
|
310 if (have_newer_gnuplot || isnan (typ)) |
|
311 withclause{data_idx} = sprintf ("with %s linestyle %d", |
|
312 style, data_idx); |
|
313 else |
|
314 withclause{data_idx} = sprintf ("with %s linetype %d", |
|
315 style, typ); |
|
316 endif |
6405
|
317 if (! isempty (obj.zdata)) |
|
318 nd = 3; |
|
319 xdat = obj.xdata(:); |
|
320 ydat = obj.ydata(:); |
|
321 zdat = obj.zdata(:); |
|
322 if (xautoscale) |
6453
|
323 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat); |
6405
|
324 endif |
|
325 if (yautoscale) |
6453
|
326 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat); |
6405
|
327 endif |
|
328 if (zautoscale) |
6453
|
329 [zmin, zmax, zminp] = get_data_limits (zmin, zmax, zminp, zdat); |
6405
|
330 endif |
|
331 data{data_idx} = [xdat, ydat, zdat]'; |
|
332 usingclause{data_idx} = "using ($1):($2):($3)"; |
|
333 fputs (plot_stream, "set parametric;\n"); |
|
334 fputs (plot_stream, "unset hidden3d;\n"); |
|
335 fputs (plot_stream, "set style data lines;\n"); |
|
336 fputs (plot_stream, "set surface;\n"); |
|
337 fputs (plot_stream, "unset contour;\n"); |
|
338 else |
|
339 nd = 2; |
|
340 xdat = obj.xdata(:); |
|
341 ydat = obj.ydata(:); |
|
342 ldat = obj.ldata; |
|
343 yerr = xerr = false; |
|
344 if (! isempty (ldat)) |
|
345 yerr = true; |
|
346 ldat = ldat(:); |
|
347 endif |
|
348 udat = obj.udata; |
|
349 if (! isempty (udat)) |
|
350 udat = udat(:); |
|
351 endif |
|
352 xldat = obj.xldata; |
|
353 if (! isempty (xldat)) |
|
354 xerr = true; |
|
355 xldat = xldat(:); |
|
356 endif |
|
357 xudat = obj.xudata; |
|
358 if (! isempty (xudat)) |
|
359 xudat = xudat(:); |
|
360 endif |
|
361 if (yerr) |
|
362 ylo = ydat-ldat; |
|
363 yhi = ydat+udat; |
|
364 if (yautoscale) |
|
365 ty = [ydat; ylo; yhi]; |
6453
|
366 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ty); |
6405
|
367 endif |
|
368 if (xerr) |
|
369 xlo = xdat-xldat; |
|
370 xhi = xdat+xudat; |
|
371 if (xautoscale) |
|
372 tx = [xdat; xlo; xhi]; |
6453
|
373 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, tx); |
6405
|
374 endif |
|
375 data{data_idx} = [xdat, ydat, xlo, xhi, ylo, yhi]'; |
|
376 usingclause{data_idx} = "using ($1):($2):($3):($4):($5):($6)"; |
6908
|
377 withclause{data_idx} = "with xyerrorbars"; |
6405
|
378 else |
6736
|
379 ## Obtain the limits based on the exact x values. |
6405
|
380 if (xautoscale) |
6453
|
381 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, |
6736
|
382 xminp, xdat); |
6405
|
383 endif |
|
384 data{data_idx} = [xdat, ydat, ylo, yhi]'; |
|
385 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
6908
|
386 withclause{data_idx} = "with yerrorbars"; |
6405
|
387 endif |
|
388 elseif (xerr) |
|
389 xlo = xdat-xldat; |
|
390 xhi = xdat+xudat; |
|
391 if (xautoscale) |
|
392 tx = [xdat; xlo; xhi]; |
6453
|
393 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, tx); |
6405
|
394 endif |
|
395 if (yautoscale) |
6453
|
396 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, |
|
397 yminp, ydat, ty); |
6405
|
398 endif |
|
399 data{data_idx} = [xdat, ydat, xlo, xhi]'; |
|
400 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
6908
|
401 withclause{data_idx} = "with xerrorbars"; |
6405
|
402 else |
|
403 if (xautoscale) |
6453
|
404 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat); |
6405
|
405 endif |
|
406 if (yautoscale) |
6453
|
407 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat); |
6405
|
408 endif |
|
409 data{data_idx} = [xdat, ydat]'; |
6809
|
410 usingclause{data_idx} = sprintf ("using ($1):($2) axes %s%s", |
|
411 xaxisloc_using, yaxisloc_using); |
6405
|
412 endif |
|
413 endif |
6465
|
414 if (! (have_newer_gnuplot || isempty (with))) |
|
415 if (isempty (withclause{data_idx})) |
6809
|
416 withclause{data_idx} = sprintf ("with %s", with); |
6465
|
417 else |
6809
|
418 withclause{data_idx} = sprintf ("%s %s", withclause{data_idx}, |
|
419 with); |
6465
|
420 endif |
|
421 endif |
6405
|
422 |
6790
|
423 case "patch" |
6885
|
424 if (! isempty (obj.zdata)) |
|
425 warning ("gnuplot (as of v4.2) supports only 2D patches, ignoring z values") |
|
426 endif |
|
427 nd = 2; |
|
428 cmap = parent_figure_obj.colormap; |
|
429 clim = axis_obj.clim; |
7020
|
430 [nr, nc] = size (obj.xdata); |
|
431 |
|
432 for i = 1 : nc |
|
433 xcol = obj.xdata(:,i); |
|
434 ycol = obj.ydata(:,i); |
|
435 |
|
436 if (xautoscale) |
|
437 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xcol); |
|
438 endif |
|
439 if (yautoscale) |
|
440 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ycol); |
|
441 endif |
|
442 |
|
443 if (! isnan (xcol) && ! isnan (ycol)) |
|
444 ## Is the patch closed or not |
|
445 data_idx++; |
|
446 is_image_data(data_idx) = false; |
|
447 parametric(data_idx) = false; |
|
448 titlespec{data_idx} = "title \"\""; |
|
449 usingclause{data_idx} = ""; |
|
450 if (isfield (obj, "facecolor") && isfield (obj, "cdata")) |
|
451 if (strncmp (obj.facecolor, "none", 4)) |
|
452 color = [1, 1, 1]; |
6885
|
453 |
7020
|
454 elseif (strncmp (obj.facecolor, "flat", 4) || |
|
455 strncmp (obj.facecolor, "interp", 6)) |
|
456 if (ndims (obj.cdata) == 2 && ... |
|
457 ((nr > 3 && size (obj.cdata, 2) == nc) ... |
|
458 || (size (obj.cdata, 1) > 1 && ... |
|
459 size (obj.cdata, 2) == nc))) |
|
460 ccol = obj.cdata (:, i); |
|
461 elseif (ndims (obj.cdata) == 3) |
|
462 ccol = permute (obj.cdata (:, i, :), [1, 3, 2]); |
|
463 else |
|
464 ccol = obj.cdata; |
|
465 endif |
|
466 if (strncmp (obj.facecolor, "flat", 4)) |
|
467 if (numel(ccol) == 3) |
|
468 color = ccol; |
|
469 else |
|
470 r = 1 + round ((size (cmap, 1) - 1) * ... |
|
471 (ccol - clim(1))/(clim(2) - clim(1))); |
|
472 r = max (1, min (r, size (cmap, 1))); |
|
473 color = cmap(r, :); |
|
474 endif |
|
475 elseif (strncmp (obj.facecolor, "interp", 6)) |
|
476 warning ("\"interp\" not supported, using 1st entry of cdata") |
|
477 r = 1 + round ((size (cmap, 1) - 1) * ccol(1)); |
|
478 r = max (1, min (r, size (cmap, 1))); |
|
479 color = cmap(r,:); |
|
480 endif |
|
481 else |
|
482 color = obj.facecolor; |
|
483 endif |
|
484 else |
|
485 color = [0, 1, 0]; |
|
486 endif |
6790
|
487 |
7020
|
488 if (have_newer_gnuplot) |
|
489 withclause{data_idx} = ... |
|
490 sprintf ("with filledcurve lc rgb \"#%02x%02x%02x\"", ... |
|
491 round (255*color)); |
|
492 else |
|
493 if (isequal (color, [0,0,0])) |
|
494 typ = -1; |
|
495 elseif (isequal (color, [1,0,0])) |
|
496 typ = 1; |
|
497 elseif (isequal (color, [0,1,0])) |
|
498 typ = 2; |
|
499 elseif (isequal (color, [0,0,1])) |
|
500 typ = 3; |
|
501 elseif (isequal (color, [1,0,1])) |
|
502 typ = 4; |
|
503 elseif (isequal (color, [0,1,1])) |
|
504 typ = 5; |
|
505 elseif (isequal (color, [1,1,1])) |
|
506 typ = -1; |
|
507 elseif (isequal (color, [1,1,0])) |
|
508 typ = 7; |
|
509 else |
|
510 typ = -1; |
|
511 endif |
|
512 withclause{data_idx} = sprintf ("with filledcurve lt %d", typ); |
|
513 endif |
|
514 data{data_idx} = [xcol, ycol]'; |
|
515 usingclause{data_idx} = "using ($1):($2)"; |
|
516 endif |
6790
|
517 |
7020
|
518 ## patch outline |
|
519 data_idx++; |
|
520 is_image_data(data_idx) = false; |
|
521 parametric(data_idx) = false; |
|
522 titlespec{data_idx} = "title \"\""; |
|
523 usingclause{data_idx} = ""; |
|
524 if (isfield (obj, "edgecolor")) |
|
525 if (strncmp (obj.edgecolor, "none", 4)) |
|
526 color = [1, 1, 1]; |
|
527 elseif (strncmp (obj.edgecolor, "flat", 4)) |
|
528 warning ("\"flat\" for edgecolor not supported"); |
|
529 color = [0, 0, 0]; |
|
530 elseif (strncmp (obj.edgecolor, "interp", 6)) |
|
531 warning ("\"interp\" for edgecolor not supported"); |
|
532 color = [0, 0, 0]; |
|
533 else |
|
534 color = obj.edgecolor; |
|
535 endif |
|
536 else |
6790
|
537 color = [0, 0, 0]; |
|
538 endif |
7020
|
539 if (have_newer_gnuplot) |
|
540 withclause{data_idx} = ... |
|
541 sprintf ("with lines lc rgb \"#%02x%02x%02x\"", ... |
|
542 round (255*color)); |
6885
|
543 else |
7020
|
544 if (isequal (color, [0,0,0])) |
|
545 typ = -1; |
|
546 elseif (isequal (color, [1,0,0])) |
|
547 typ = 1; |
|
548 elseif (isequal (color, [0,1,0])) |
|
549 typ = 2; |
|
550 elseif (isequal (color, [0,0,1])) |
|
551 typ = 3; |
|
552 elseif (isequal (color, [1,0,1])) |
|
553 typ = 4; |
|
554 elseif (isequal (color, [0,1,1])) |
|
555 typ = 5; |
|
556 elseif (isequal (color, [1,1,1])) |
|
557 typ = -1; |
|
558 elseif (isequal (color, [1,1,0])) |
|
559 typ = 7; |
|
560 else |
|
561 typ = -1; |
|
562 endif |
|
563 withclause{data_idx} = sprintf ("with lines lt %d", typ); |
6885
|
564 endif |
6790
|
565 |
7020
|
566 if (!isnan (xcol) && !isnan (ycol)) |
|
567 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]'; |
|
568 else |
|
569 data{data_idx} = [xcol, ycol]'; |
|
570 endif |
|
571 usingclause{data_idx} = "using ($1):($2)"; |
|
572 endfor |
6790
|
573 |
6405
|
574 case "surface" |
|
575 data_idx++; |
6464
|
576 is_image_data(data_idx) = false; |
6861
|
577 parametric(data_idx) = false; |
6465
|
578 [style, typ, with] = do_linestyle_command (obj, data_idx, plot_stream); |
6405
|
579 if (isempty (obj.keylabel)) |
|
580 titlespec{data_idx} = "title \"\""; |
|
581 else |
7094
|
582 tmp = undo_string_escapes (obj.keylabel); |
|
583 titlespec{data_idx} = strcat ("title \"", tmp, "\""); |
6405
|
584 endif |
|
585 usingclause{data_idx} = ""; |
6425
|
586 if (have_newer_gnuplot || isnan (typ)) |
|
587 withclause{data_idx} = sprintf ("with %s linestyle %d", |
|
588 style, data_idx); |
|
589 else |
6465
|
590 withclause{data_idx} = sprintf ("with %s linetype %d %s", |
|
591 style, typ, with); |
6425
|
592 endif |
6405
|
593 nd = 3; |
|
594 xdat = obj.xdata; |
|
595 ydat = obj.ydata; |
|
596 zdat = obj.zdata; |
|
597 if (xautoscale) |
|
598 tx = xdat(:); |
6453
|
599 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, tx); |
6405
|
600 endif |
|
601 if (yautoscale) |
|
602 ty = ydat(:); |
6453
|
603 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ty); |
6405
|
604 endif |
|
605 if (zautoscale) |
|
606 tz = zdat(:); |
6453
|
607 [zmin, zmax, zminp] = get_data_limits (zmin, zmax, zminp, tz); |
6405
|
608 endif |
|
609 err = false; |
|
610 if (isvector (xdat) && isvector (ydat) && ismatrix (zdat)) |
|
611 if (rows (zdat) == length (ydat) && columns (zdat) == length (xdat)) |
|
612 [xdat, ydat] = meshgrid (xdat, ydat); |
|
613 else |
|
614 err = true; |
|
615 endif |
|
616 elseif (ismatrix (xdat) && ismatrix (ydat) && ismatrix (zdat)) |
|
617 if (! (size_equal (xdat, ydat) && size_equal (xdat, zdat))) |
|
618 err = true; |
|
619 endif |
|
620 else |
|
621 err = true; |
|
622 endif |
|
623 if (err) |
|
624 error ("__go_draw_axes__: invalid grid data"); |
|
625 endif |
|
626 xlen = columns (zdat); |
|
627 ylen = rows (zdat); |
|
628 if (xlen == columns (xdat) && xlen == columns (ydat) |
|
629 && ylen == rows (xdat) && ylen == rows (ydat)) |
|
630 len = 3 * xlen; |
|
631 zz = zeros (ylen, len); |
|
632 k = 1; |
|
633 for kk = 1:3:len |
|
634 zz(:,kk) = xdat(:,k); |
|
635 zz(:,kk+1) = ydat(:,k); |
|
636 zz(:,kk+2) = zdat(:,k); |
|
637 k++; |
|
638 endfor |
|
639 data{data_idx} = zz; |
|
640 endif |
|
641 usingclause{data_idx} = "using ($1):($2):($3)"; |
|
642 withclause{data_idx} = "with line palette"; |
|
643 |
|
644 fputs (plot_stream, "unset parametric;\n"); |
|
645 fputs (plot_stream, "set hidden3d;\n"); |
|
646 fputs (plot_stream, "set style data lines;\n"); |
|
647 fputs (plot_stream, "set surface;\n"); |
|
648 fputs (plot_stream, "unset contour;\n"); |
6963
|
649 fprintf (plot_stream, "set cbrange [%g:%g];\n", zmin, zmax); |
6788
|
650 |
|
651 if (have_newer_gnuplot) |
|
652 surf_colormap = parent_figure_obj.colormap; |
|
653 palette_size = rows (surf_colormap); |
|
654 fprintf (plot_stream, |
|
655 "set palette positive color model RGB maxcolors %i;\n", |
|
656 palette_size); |
|
657 fprintf (plot_stream, |
|
658 "set palette file \"-\" binary record=%d using 1:2:3:4;\n", |
|
659 palette_size); |
|
660 fwrite (plot_stream, [1:palette_size; surf_colormap'], "float32"); |
|
661 else |
|
662 fputs (plot_stream, "set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n"); |
|
663 endif |
6405
|
664 fputs (plot_stream, "unset colorbox;\n"); |
|
665 |
|
666 case "text" |
|
667 lpos = obj.position; |
|
668 label = obj.string; |
|
669 halign = obj.horizontalalignment; |
6724
|
670 angle = obj.rotation; |
6752
|
671 units = obj.units; |
6829
|
672 color = obj.color; |
6758
|
673 if (strcmpi (units, "normalized")) |
6752
|
674 units = "graph"; |
|
675 else |
|
676 units = ""; |
|
677 endif |
|
678 |
6829
|
679 if (isnumeric (color)) |
|
680 if (have_newer_gnuplot) |
|
681 colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"", |
|
682 round (255*color)); |
|
683 else |
|
684 if (isequal (color, [0,0,0])) |
|
685 typ = -1; |
|
686 elseif (isequal (color, [1,0,0])) |
|
687 typ = 1; |
|
688 elseif (isequal (color, [0,1,0])) |
|
689 typ = 2; |
|
690 elseif (isequal (color, [0,0,1])) |
|
691 typ = 3; |
|
692 elseif (isequal (color, [1,0,1])) |
|
693 typ = 4; |
|
694 elseif (isequal (color, [0,1,1])) |
|
695 typ = 5; |
|
696 elseif (isequal (color, [1,1,1])) |
|
697 typ = -1; |
|
698 elseif (isequal (color, [1,1,0])) |
|
699 typ = 7; |
|
700 else |
|
701 typ = -1; |
|
702 endif |
|
703 colorspec = sprintf ("textcolor lt %d", typ); |
|
704 endif |
|
705 endif |
|
706 |
6405
|
707 if (nd == 3) |
6724
|
708 fprintf (plot_stream, |
6914
|
709 "set label \"%s\" at %s %.15g,%.15g,%.15g %s rotate by %f %s;\n", |
6752
|
710 undo_string_escapes (label), units, |
6829
|
711 lpos(1), lpos(2), lpos(3), halign, angle, colorspec); |
6405
|
712 else |
6724
|
713 fprintf (plot_stream, |
6914
|
714 "set label \"%s\" at %s %.15g,%.15g %s rotate by %f %s;\n", |
6752
|
715 undo_string_escapes (label), units, |
6829
|
716 lpos(1), lpos(2), halign, angle, colorspec); |
6405
|
717 endif |
|
718 |
|
719 otherwise |
|
720 error ("__go_draw_axes__: unknown object class, %s", |
|
721 obj.type); |
|
722 endswitch |
|
723 |
|
724 endfor |
|
725 |
|
726 have_data = ! isempty (data); |
|
727 |
|
728 if (xautoscale && have_data) |
|
729 xlim = get_axis_limits (xmin, xmax, xminp, xlogscale); |
7008
|
730 if (isempty (xlim)) |
|
731 return; |
|
732 endif |
6405
|
733 set (h, "xlim", xlim, "xlimmode", "auto"); |
|
734 else |
|
735 xlim = axis_obj.xlim; |
|
736 endif |
6758
|
737 if (strcmpi (axis_obj.xdir, "reverse")) |
6405
|
738 xdir = "reverse"; |
|
739 else |
|
740 xdir = "noreverse"; |
|
741 endif |
6942
|
742 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", xaxisloc, xlim, xdir); |
6405
|
743 |
|
744 if (yautoscale && have_data) |
|
745 ylim = get_axis_limits (ymin, ymax, yminp, ylogscale); |
7008
|
746 if (isempty (ylim)) |
|
747 return; |
|
748 endif |
6405
|
749 set (h, "ylim", ylim, "ylimmode", "auto"); |
|
750 else |
|
751 ylim = axis_obj.ylim; |
|
752 endif |
6758
|
753 if (strcmpi (axis_obj.ydir, "reverse")) |
6405
|
754 ydir = "reverse"; |
|
755 else |
|
756 ydir = "noreverse"; |
|
757 endif |
6942
|
758 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", yaxisloc, ylim, ydir); |
6405
|
759 |
|
760 if (nd == 3) |
|
761 if (zautoscale && have_data) |
|
762 zlim = get_axis_limits (zmin, zmax, zminp, zlogscale); |
7008
|
763 if (isempty (zlim)) |
|
764 return; |
|
765 endif |
6405
|
766 set (h, "zlim", zlim, "zlimmode", "auto"); |
|
767 else |
|
768 zlim = axis_obj.zlim; |
|
769 endif |
6758
|
770 if (strcmpi (axis_obj.zdir, "reverse")) |
6405
|
771 zdir = "reverse"; |
|
772 else |
|
773 zdir = "noreverse"; |
|
774 endif |
6942
|
775 fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir); |
6405
|
776 endif |
|
777 |
6758
|
778 if (strcmpi (axis_obj.box, "on")) |
6405
|
779 if (nd == 3) |
|
780 fputs (plot_stream, "set border 4095;\n"); |
|
781 else |
|
782 fputs (plot_stream, "set border 431;\n"); |
|
783 endif |
|
784 else |
|
785 if (nd == 3) |
|
786 fputs (plot_stream, "set border 895;\n"); |
|
787 else |
|
788 fputs (plot_stream, "set border 3;\n"); |
|
789 fputs (plot_stream, "set xtics nomirror; set ytics nomirror;\n"); |
|
790 endif |
|
791 endif |
|
792 |
7060
|
793 if (strcmpi (axis_obj.visible, "off")) |
|
794 fputs (plot_stream, "unset border; unset tics\n"); |
|
795 endif |
|
796 |
6758
|
797 if (strcmpi (axis_obj.key, "on")) |
|
798 if (strcmpi (axis_obj.keybox, "on")) |
6405
|
799 box = "box"; |
|
800 else |
|
801 box = "nobox"; |
|
802 endif |
|
803 inout = "inside"; |
6977
|
804 keypos = axis_obj.keypos; |
|
805 if (ischar (keypos)) |
|
806 keypos = lower (keypos); |
|
807 keyout = findstr (keypos, "outside"); |
|
808 if (! isempty (keyout)) |
|
809 inout = "outside"; |
|
810 keypos = keypos (1:keyout-1); |
|
811 endif |
|
812 endif |
|
813 switch (keypos) |
6405
|
814 case -1 |
6977
|
815 pos = "right top"; |
6405
|
816 inout = "outside"; |
|
817 case 1 |
|
818 pos = "right top"; |
|
819 case 2 |
|
820 pos = "left top"; |
|
821 case 3 |
|
822 pos = "left bottom"; |
6977
|
823 case {4, 0} |
6405
|
824 pos = "right bottom"; |
6977
|
825 case "north" |
|
826 pos = "center top"; |
|
827 case "south" |
|
828 pos = "center bottom"; |
|
829 case "east" |
|
830 pos = "right center"; |
|
831 case "west" |
|
832 pos = "left center"; |
|
833 case "northeast" |
|
834 pos = "right top"; |
|
835 case "northwest" |
|
836 pos = "left top"; |
|
837 case "southeast" |
|
838 pos = "right bottom"; |
|
839 case "southwest" |
|
840 pos = "left bottom"; |
|
841 case "best" |
|
842 pos = ""; |
|
843 warning ("legend: 'Best' not yet implemented for location specifier.\n"); |
|
844 ## least conflict with data in plot |
|
845 ## least unused space outside plot |
6405
|
846 otherwise |
|
847 pos = ""; |
|
848 endswitch |
|
849 if (! have_newer_gnuplot) |
|
850 inout = ""; |
|
851 endif |
|
852 fprintf (plot_stream, "set key %s %s %s;\n", inout, pos, box); |
|
853 else |
|
854 fputs (plot_stream, "unset key;\n"); |
|
855 endif |
|
856 |
|
857 fputs (plot_stream, "set style data lines;\n"); |
|
858 |
|
859 if (! use_gnuplot_for_images) |
|
860 for i = 1:ximg_data_idx |
|
861 view_fcn (xlim, ylim, ximg_data{i}, view_zoom, view_cmd); |
|
862 endfor |
|
863 endif |
|
864 |
|
865 if (have_data) |
|
866 |
|
867 if (nd == 2) |
|
868 plot_cmd = "plot"; |
|
869 else |
|
870 plot_cmd = "splot"; |
|
871 rot_x = 90 - axis_obj.view(2); |
|
872 rot_z = axis_obj.view(1); |
|
873 while (rot_z < 0) |
|
874 rot_z += 360; |
|
875 endwhile |
6461
|
876 fputs (plot_stream, "set ticslevel 0;\n"); |
6914
|
877 fprintf (plot_stream, "set view %.15g, %.15g;\n", rot_x, rot_z); |
6405
|
878 endif |
6611
|
879 fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd, |
6464
|
880 usingclause{1}, titlespec{1}, withclause{1}); |
6405
|
881 for i = 2:data_idx |
6611
|
882 fprintf (plot_stream, ", \"-\" %s %s %s \\\n", |
6464
|
883 usingclause{i}, titlespec{i}, withclause{i}); |
6405
|
884 endfor |
|
885 fputs (plot_stream, ";\n"); |
|
886 for i = 1:data_idx |
6464
|
887 if (is_image_data(i)) |
|
888 fwrite (plot_stream, data{i}, "float32"); |
|
889 else |
6510
|
890 __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i)); |
6405
|
891 endif |
|
892 endfor |
6431
|
893 else |
|
894 fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n"); |
6405
|
895 endif |
|
896 |
|
897 fflush (plot_stream); |
|
898 |
|
899 else |
|
900 print_usage (); |
|
901 endif |
|
902 |
|
903 endfunction |
|
904 |
6453
|
905 function [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat, tx) |
|
906 xdat = xdat(! isinf (xdat)); |
|
907 xmin = min (xmin, min (xdat)); |
|
908 xmax = max (xmax, max (xdat)); |
|
909 if (nargin == 5) |
|
910 tx = tx(! isinf (xdat) & tx > 0); |
7012
|
911 if (! isempty (tx)) |
|
912 xminp = min (xminp, min (tx)); |
|
913 endif |
6453
|
914 else |
7012
|
915 tmp = min (xdat(xdat > 0)); |
|
916 if (! isempty (tmp)) |
|
917 xminp = min (xminp, tmp); |
|
918 endif |
6453
|
919 endif |
|
920 endfunction |
|
921 |
6405
|
922 ## Attempt to make "nice" limits from the actual max and min of the |
|
923 ## data. For log plots, we will also use the smallest strictly positive |
|
924 ## value. |
|
925 |
|
926 function lim = get_axis_limits (min_val, max_val, min_pos, logscale) |
|
927 |
|
928 if (logscale) |
7012
|
929 if (isinf (min_pos)) |
7008
|
930 lim = []; |
6405
|
931 warning ("axis: logscale with no positive values to plot"); |
7008
|
932 return; |
6405
|
933 endif |
6527
|
934 if (min_val <= 0) |
7008
|
935 warning ("axis: omitting nonpositive data in log plot"); |
6405
|
936 min_val = min_pos; |
|
937 endif |
6512
|
938 ## FIXME -- maybe this test should also be relative? |
|
939 if (abs (min_val - max_val) < sqrt (eps)) |
|
940 min_val *= 0.9; |
|
941 max_val *= 1.1; |
6405
|
942 endif |
|
943 min_val = 10 ^ floor (log10 (min_val)); |
|
944 max_val = 10 ^ ceil (log10 (max_val)); |
|
945 else |
|
946 if (min_val == 0 && max_val == 0) |
|
947 min_val = -1; |
|
948 max_val = 1; |
6512
|
949 ## FIXME -- maybe this test should also be relative? |
|
950 elseif (abs (min_val - max_val) < sqrt (eps)) |
|
951 min_val -= 0.1 * abs (min_val); |
|
952 max_val += 0.1 * abs (max_val); |
6405
|
953 endif |
|
954 ## FIXME -- to do a better job, we should consider the tic spacing. |
|
955 scale = 10 ^ floor (log10 (max_val - min_val) - 1); |
|
956 min_val = scale * floor (min_val / scale); |
|
957 max_val = scale * ceil (max_val / scale); |
|
958 endif |
|
959 |
|
960 lim = [min_val, max_val]; |
|
961 |
|
962 endfunction |
|
963 |
6465
|
964 function [style, typ, with] = do_linestyle_command (obj, idx, plot_stream) |
6405
|
965 |
6413
|
966 persistent have_newer_gnuplot ... |
|
967 = compare_versions (__gnuplot_version__ (), "4.0", ">"); |
6405
|
968 |
|
969 if (have_newer_gnuplot) |
|
970 fprintf (plot_stream, "set style line %d default;\n", idx); |
|
971 endif |
|
972 fprintf (plot_stream, "set style line %d", idx); |
|
973 |
|
974 found_style = false; |
6425
|
975 typ = NaN; |
6465
|
976 with = ""; |
6405
|
977 |
6425
|
978 if (isfield (obj, "color")) |
6405
|
979 color = obj.color; |
|
980 if (isnumeric (color)) |
6425
|
981 if (have_newer_gnuplot) |
|
982 fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", |
|
983 round (255*color)); |
|
984 else |
|
985 if (isequal (color, [0,0,0])) |
|
986 typ = -1; |
|
987 elseif (isequal (color, [1,0,0])) |
|
988 typ = 1; |
|
989 elseif (isequal (color, [0,1,0])) |
|
990 typ = 2; |
|
991 elseif (isequal (color, [0,0,1])) |
|
992 typ = 3; |
|
993 elseif (isequal (color, [1,0,1])) |
|
994 typ = 4; |
|
995 elseif (isequal (color, [0,1,1])) |
|
996 typ = 5; |
|
997 elseif (isequal (color, [1,1,1])) |
|
998 typ = 6; |
|
999 elseif (isequal (color, [1,1,0])) |
|
1000 typ = 7; |
|
1001 else |
|
1002 typ = 2; |
|
1003 endif |
|
1004 endif |
6405
|
1005 endif |
|
1006 found_style = true; |
|
1007 endif |
|
1008 |
|
1009 if (isfield (obj, "linestyle")) |
|
1010 switch (obj.linestyle) |
|
1011 case "-" |
6415
|
1012 lt = "1"; |
6405
|
1013 case "--" |
6415
|
1014 lt = "2"; |
6405
|
1015 case ":" |
6415
|
1016 lt = "3"; |
6405
|
1017 case "-." |
6415
|
1018 lt = "6"; |
6405
|
1019 case "none" |
|
1020 lt = ""; |
|
1021 otherwise |
|
1022 lt = ""; |
|
1023 endswitch |
6843
|
1024 |
|
1025 ## FIXME -- linetype is currently broken, since it disables the |
|
1026 ## gnuplot default dashed and solid linestyles with the only |
|
1027 ## benefit of being able to specify '--' and get a single sized |
|
1028 ## dashed line of identical dash pattern for all called this way. |
|
1029 ## All dash patterns are a subset of "with lines" and none of the |
|
1030 ## lt specifications will correctly propagate into the x11 terminal |
|
1031 ## or the print command. Therefore, it is currently disabled in |
|
1032 ## order to allow print (..., "-dashed") etc. to work correctly. |
|
1033 |
|
1034 ## if (! isempty (lt)) |
|
1035 ## fprintf (plot_stream, " linetype %s", lt); |
|
1036 ## found_style = true; |
|
1037 ## endif |
|
1038 |
6405
|
1039 else |
|
1040 lt = ""; |
|
1041 endif |
|
1042 |
|
1043 if (isfield (obj, "linewidth")) |
6465
|
1044 if (have_newer_gnuplot) |
|
1045 fprintf (plot_stream, " linewidth %f", obj.linewidth); |
|
1046 else |
|
1047 with = sprintf ("%s lw %f", with, obj.linewidth); |
|
1048 endif |
6405
|
1049 found_style = true; |
|
1050 endif |
|
1051 |
|
1052 if (isfield (obj, "marker")) |
|
1053 switch (obj.marker) |
|
1054 case "+" |
|
1055 pt = "1"; |
|
1056 case "o" |
6413
|
1057 pt = "6"; |
6405
|
1058 case "*" |
|
1059 pt = "3"; |
|
1060 case "." |
7078
|
1061 pt = "0"; |
6405
|
1062 case "x" |
|
1063 pt = "2"; |
|
1064 case {"square", "s"} |
|
1065 pt = "5"; |
|
1066 case {"diamond", "d"} |
|
1067 pt = "13"; |
|
1068 case "^" |
|
1069 pt = "9"; |
|
1070 case "v" |
|
1071 pt = "11"; |
|
1072 case ">" |
|
1073 pt = "8"; |
|
1074 case "<" |
|
1075 pt = "10"; |
|
1076 case {"pentagram", "p"} |
|
1077 pt = "4"; |
|
1078 case {"hexagram", "h"} |
6413
|
1079 pt = "12"; |
6405
|
1080 case "none" |
|
1081 pt = ""; |
|
1082 otherwise |
|
1083 pt = ""; |
|
1084 endswitch |
|
1085 if (! isempty (pt)) |
6465
|
1086 if (have_newer_gnuplot) |
|
1087 fprintf (plot_stream, " pointtype %s", pt); |
|
1088 else |
|
1089 with = sprintf ("%s pt %s", with, pt); |
|
1090 endif |
6405
|
1091 found_style = true; |
|
1092 endif |
|
1093 else |
|
1094 pt = ""; |
|
1095 endif |
|
1096 |
|
1097 style = "lines"; |
|
1098 if (isempty (lt)) |
|
1099 if (! isempty (pt)) |
|
1100 style = "points"; |
|
1101 endif |
|
1102 elseif (! isempty (pt)) |
|
1103 style = "linespoints"; |
|
1104 endif |
|
1105 |
6465
|
1106 if (isfield (obj, "markersize")) |
|
1107 if (have_newer_gnuplot) |
|
1108 fprintf (plot_stream, " pointsize %f", obj.markersize); |
|
1109 else |
6758
|
1110 if (! strcmpi (style, "lines")) |
6465
|
1111 with = sprintf ("%s ps %f", with, obj.markersize); |
|
1112 endif |
|
1113 endif |
|
1114 found_style = true; |
|
1115 endif |
|
1116 |
6405
|
1117 if (have_newer_gnuplot && ! found_style) |
|
1118 fputs (plot_stream, " default"); |
|
1119 endif |
|
1120 |
|
1121 fputs (plot_stream, ";\n"); |
|
1122 |
|
1123 endfunction |
6510
|
1124 |
|
1125 function __gnuplot_write_data__ (plot_stream, data, nd, parametric) |
|
1126 |
|
1127 ## DATA is already transposed. |
|
1128 |
|
1129 ## FIXME -- this may need to be converted to C++ for speed. |
|
1130 |
6605
|
1131 ## Convert NA elements to normal NaN values because fprintf writes |
|
1132 ## "NA" and that confuses gnuplot. |
|
1133 idx = find (isna (data)); |
|
1134 if (any (idx)) |
|
1135 data(idx) = NaN; |
|
1136 endif |
|
1137 |
6510
|
1138 if (nd == 2) |
|
1139 nan_elts = find (sum (isnan (data))); |
6914
|
1140 fmt = strcat (repmat ("%.15g ", 1, rows (data)), "\n"); |
6510
|
1141 if (isempty (nan_elts)) |
|
1142 fprintf (plot_stream, fmt, data); |
|
1143 else |
|
1144 n = columns (data); |
|
1145 have_nans = true; |
|
1146 num_nan_elts = numel (nan_elts); |
|
1147 k = 1; |
|
1148 for i = 1:n |
|
1149 if (have_nans && i == nan_elts(k)) |
|
1150 fputs (plot_stream, "\n"); |
|
1151 have_nans = ++k <= num_nan_elts; |
|
1152 else |
|
1153 fprintf (plot_stream, fmt, data(:,i)); |
|
1154 endif |
|
1155 endfor |
|
1156 endif |
|
1157 else |
|
1158 ## FIXME -- handle NaNs here too? |
|
1159 if (parametric) |
6914
|
1160 fprintf (plot_stream, "%.15g %.15g %.15g\n", data); |
6510
|
1161 else |
|
1162 nc = columns (data); |
|
1163 for j = 1:3:nc |
6914
|
1164 fprintf (plot_stream, "%.15g %.15g %.15g\n", data(:,j:j+2)'); |
6510
|
1165 fputs (plot_stream, "\n"); |
|
1166 endfor |
|
1167 endif |
|
1168 endif |
|
1169 fputs (plot_stream, "e\n"); |
|
1170 |
|
1171 endfunction |
6745
|
1172 |
|
1173 function do_tics (obj, plot_stream) |
6809
|
1174 if (strcmpi (obj.xaxislocation, "top")) |
|
1175 do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, |
|
1176 "x2", plot_stream); |
|
1177 do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, |
|
1178 "x", plot_stream); |
|
1179 else |
|
1180 do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, |
|
1181 "x", plot_stream); |
|
1182 do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, |
|
1183 "x2", plot_stream); |
|
1184 endif |
|
1185 if (strcmpi (obj.yaxislocation, "right")) |
|
1186 do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, |
|
1187 "y2", plot_stream); |
|
1188 do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, |
|
1189 "y", plot_stream); |
|
1190 else |
|
1191 do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, |
|
1192 "y", plot_stream); |
|
1193 do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, |
|
1194 "y2", plot_stream); |
|
1195 endif |
6745
|
1196 do_tics_1 (obj.ztickmode, obj.ztick, obj.zticklabelmode, obj.zticklabel, |
|
1197 "z", plot_stream); |
|
1198 endfunction |
|
1199 |
|
1200 function do_tics_1 (ticmode, tics, labelmode, labels, ax, plot_stream) |
6758
|
1201 if (strcmpi (ticmode, "manual")) |
6745
|
1202 if (isempty (tics)) |
|
1203 fprintf (plot_stream, "unset %stics;\n", ax); |
6758
|
1204 elseif (strcmpi (labelmode, "manual") && ! isempty (labels)) |
6751
|
1205 if (ischar (labels)) |
|
1206 labels = cellstr (labels); |
|
1207 endif |
6745
|
1208 if (iscellstr (labels)) |
6751
|
1209 k = 1; |
|
1210 ntics = numel (tics); |
|
1211 nlabels = numel (labels); |
6745
|
1212 fprintf (plot_stream, "set format %s \"%%s\";\n", ax); |
|
1213 fprintf (plot_stream, "set %stics (", ax); |
|
1214 for i = 1:ntics |
6920
|
1215 fprintf (plot_stream, " \"%s\" %g", labels(k++), tics(i)) |
6745
|
1216 if (i < ntics) |
|
1217 fputs (plot_stream, ", "); |
|
1218 endif |
|
1219 if (k > nlabels) |
|
1220 k = 1; |
|
1221 endif |
|
1222 endfor |
|
1223 fputs (plot_stream, ");\n"); |
|
1224 else |
|
1225 error ("unsupported type of ticklabel"); |
|
1226 endif |
|
1227 else |
6920
|
1228 fprintf (plot_stream, "set format %s \"%%g\";\n", ax); |
6745
|
1229 fprintf (plot_stream, "set %stics (", ax); |
6920
|
1230 fprintf (plot_stream, " %g,", tics(1:end-1)); |
|
1231 fprintf (plot_stream, " %g);\n", tics(end)); |
6745
|
1232 endif |
|
1233 else |
6920
|
1234 fprintf (plot_stream, "set format %s \"%%g\";\n", ax); |
6745
|
1235 fprintf (plot_stream, "set %stics;\n", ax); |
|
1236 endif |
|
1237 endfunction |