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