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