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