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