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