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"); |
6963
|
616 fprintf (plot_stream, "set cbrange [%g:%g];\n", zmin, zmax); |
6788
|
617 |
|
618 if (have_newer_gnuplot) |
|
619 surf_colormap = parent_figure_obj.colormap; |
|
620 palette_size = rows (surf_colormap); |
|
621 fprintf (plot_stream, |
|
622 "set palette positive color model RGB maxcolors %i;\n", |
|
623 palette_size); |
|
624 fprintf (plot_stream, |
|
625 "set palette file \"-\" binary record=%d using 1:2:3:4;\n", |
|
626 palette_size); |
|
627 fwrite (plot_stream, [1:palette_size; surf_colormap'], "float32"); |
|
628 else |
|
629 fputs (plot_stream, "set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n"); |
|
630 endif |
6405
|
631 fputs (plot_stream, "unset colorbox;\n"); |
|
632 |
|
633 case "text" |
|
634 lpos = obj.position; |
|
635 label = obj.string; |
|
636 halign = obj.horizontalalignment; |
6724
|
637 angle = obj.rotation; |
6752
|
638 units = obj.units; |
6829
|
639 color = obj.color; |
6758
|
640 if (strcmpi (units, "normalized")) |
6752
|
641 units = "graph"; |
|
642 else |
|
643 units = ""; |
|
644 endif |
|
645 |
6829
|
646 if (isnumeric (color)) |
|
647 if (have_newer_gnuplot) |
|
648 colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"", |
|
649 round (255*color)); |
|
650 else |
|
651 if (isequal (color, [0,0,0])) |
|
652 typ = -1; |
|
653 elseif (isequal (color, [1,0,0])) |
|
654 typ = 1; |
|
655 elseif (isequal (color, [0,1,0])) |
|
656 typ = 2; |
|
657 elseif (isequal (color, [0,0,1])) |
|
658 typ = 3; |
|
659 elseif (isequal (color, [1,0,1])) |
|
660 typ = 4; |
|
661 elseif (isequal (color, [0,1,1])) |
|
662 typ = 5; |
|
663 elseif (isequal (color, [1,1,1])) |
|
664 typ = -1; |
|
665 elseif (isequal (color, [1,1,0])) |
|
666 typ = 7; |
|
667 else |
|
668 typ = -1; |
|
669 endif |
|
670 colorspec = sprintf ("textcolor lt %d", typ); |
|
671 endif |
|
672 endif |
|
673 |
6405
|
674 if (nd == 3) |
6724
|
675 fprintf (plot_stream, |
6914
|
676 "set label \"%s\" at %s %.15g,%.15g,%.15g %s rotate by %f %s;\n", |
6752
|
677 undo_string_escapes (label), units, |
6829
|
678 lpos(1), lpos(2), lpos(3), halign, angle, colorspec); |
6405
|
679 else |
6724
|
680 fprintf (plot_stream, |
6914
|
681 "set label \"%s\" at %s %.15g,%.15g %s rotate by %f %s;\n", |
6752
|
682 undo_string_escapes (label), units, |
6829
|
683 lpos(1), lpos(2), halign, angle, colorspec); |
6405
|
684 endif |
|
685 |
|
686 otherwise |
|
687 error ("__go_draw_axes__: unknown object class, %s", |
|
688 obj.type); |
|
689 endswitch |
|
690 |
|
691 endfor |
|
692 |
|
693 have_data = ! isempty (data); |
|
694 |
|
695 if (xautoscale && have_data) |
|
696 xlim = get_axis_limits (xmin, xmax, xminp, xlogscale); |
|
697 set (h, "xlim", xlim, "xlimmode", "auto"); |
|
698 else |
|
699 xlim = axis_obj.xlim; |
|
700 endif |
6758
|
701 if (strcmpi (axis_obj.xdir, "reverse")) |
6405
|
702 xdir = "reverse"; |
|
703 else |
|
704 xdir = "noreverse"; |
|
705 endif |
6942
|
706 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", xaxisloc, xlim, xdir); |
6405
|
707 |
|
708 if (yautoscale && have_data) |
|
709 ylim = get_axis_limits (ymin, ymax, yminp, ylogscale); |
|
710 set (h, "ylim", ylim, "ylimmode", "auto"); |
|
711 else |
|
712 ylim = axis_obj.ylim; |
|
713 endif |
6758
|
714 if (strcmpi (axis_obj.ydir, "reverse")) |
6405
|
715 ydir = "reverse"; |
|
716 else |
|
717 ydir = "noreverse"; |
|
718 endif |
6942
|
719 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", yaxisloc, ylim, ydir); |
6405
|
720 |
|
721 if (nd == 3) |
|
722 if (zautoscale && have_data) |
|
723 zlim = get_axis_limits (zmin, zmax, zminp, zlogscale); |
|
724 set (h, "zlim", zlim, "zlimmode", "auto"); |
|
725 else |
|
726 zlim = axis_obj.zlim; |
|
727 endif |
6758
|
728 if (strcmpi (axis_obj.zdir, "reverse")) |
6405
|
729 zdir = "reverse"; |
|
730 else |
|
731 zdir = "noreverse"; |
|
732 endif |
6942
|
733 fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir); |
6405
|
734 endif |
|
735 |
6758
|
736 if (strcmpi (axis_obj.box, "on")) |
6405
|
737 if (nd == 3) |
|
738 fputs (plot_stream, "set border 4095;\n"); |
|
739 else |
|
740 fputs (plot_stream, "set border 431;\n"); |
|
741 endif |
|
742 else |
|
743 if (nd == 3) |
|
744 fputs (plot_stream, "set border 895;\n"); |
|
745 else |
|
746 fputs (plot_stream, "set border 3;\n"); |
|
747 fputs (plot_stream, "set xtics nomirror; set ytics nomirror;\n"); |
|
748 endif |
|
749 endif |
|
750 |
6758
|
751 if (strcmpi (axis_obj.key, "on")) |
|
752 if (strcmpi (axis_obj.keybox, "on")) |
6405
|
753 box = "box"; |
|
754 else |
|
755 box = "nobox"; |
|
756 endif |
|
757 inout = "inside"; |
|
758 switch (axis_obj.keypos) |
|
759 case -1 |
|
760 pos = "right bottom"; |
|
761 inout = "outside"; |
|
762 case 1 |
|
763 pos = "right top"; |
|
764 case 2 |
|
765 pos = "left top"; |
|
766 case 3 |
|
767 pos = "left bottom"; |
|
768 case 4 |
|
769 pos = "right bottom"; |
|
770 otherwise |
|
771 pos = ""; |
|
772 endswitch |
|
773 if (! have_newer_gnuplot) |
|
774 inout = ""; |
|
775 endif |
|
776 fprintf (plot_stream, "set key %s %s %s;\n", inout, pos, box); |
|
777 else |
|
778 fputs (plot_stream, "unset key;\n"); |
|
779 endif |
|
780 |
|
781 fputs (plot_stream, "set style data lines;\n"); |
|
782 |
|
783 if (! use_gnuplot_for_images) |
|
784 for i = 1:ximg_data_idx |
|
785 view_fcn (xlim, ylim, ximg_data{i}, view_zoom, view_cmd); |
|
786 endfor |
|
787 endif |
|
788 |
|
789 if (have_data) |
|
790 |
|
791 if (nd == 2) |
|
792 plot_cmd = "plot"; |
|
793 else |
|
794 plot_cmd = "splot"; |
|
795 rot_x = 90 - axis_obj.view(2); |
|
796 rot_z = axis_obj.view(1); |
|
797 while (rot_z < 0) |
|
798 rot_z += 360; |
|
799 endwhile |
6461
|
800 fputs (plot_stream, "set ticslevel 0;\n"); |
6914
|
801 fprintf (plot_stream, "set view %.15g, %.15g;\n", rot_x, rot_z); |
6405
|
802 endif |
6611
|
803 fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd, |
6464
|
804 usingclause{1}, titlespec{1}, withclause{1}); |
6405
|
805 for i = 2:data_idx |
6611
|
806 fprintf (plot_stream, ", \"-\" %s %s %s \\\n", |
6464
|
807 usingclause{i}, titlespec{i}, withclause{i}); |
6405
|
808 endfor |
|
809 fputs (plot_stream, ";\n"); |
|
810 for i = 1:data_idx |
6464
|
811 if (is_image_data(i)) |
|
812 fwrite (plot_stream, data{i}, "float32"); |
|
813 else |
6510
|
814 __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i)); |
6405
|
815 endif |
|
816 endfor |
6431
|
817 else |
|
818 fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n"); |
6405
|
819 endif |
|
820 |
|
821 fflush (plot_stream); |
|
822 |
|
823 else |
|
824 print_usage (); |
|
825 endif |
|
826 |
|
827 endfunction |
|
828 |
6453
|
829 function [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat, tx) |
|
830 xdat = xdat(! isinf (xdat)); |
|
831 xmin = min (xmin, min (xdat)); |
|
832 xmax = max (xmax, max (xdat)); |
|
833 if (nargin == 5) |
|
834 tx = tx(! isinf (xdat) & tx > 0); |
|
835 xminp = min (xminp, min (tx)); |
|
836 else |
|
837 xminp = min (xminp, min (xdat(xdat>0))); |
|
838 endif |
|
839 endfunction |
|
840 |
6405
|
841 ## Attempt to make "nice" limits from the actual max and min of the |
|
842 ## data. For log plots, we will also use the smallest strictly positive |
|
843 ## value. |
|
844 |
|
845 function lim = get_axis_limits (min_val, max_val, min_pos, logscale) |
|
846 |
|
847 if (logscale) |
|
848 if (isinf (min_pos)) |
|
849 warning ("axis: logscale with no positive values to plot"); |
|
850 endif |
6527
|
851 if (min_val <= 0) |
6405
|
852 min_val = min_pos; |
6527
|
853 if (max_val <= 0) |
6405
|
854 max_val = min_pos; |
|
855 endif |
6527
|
856 warning ("axis: omitting nonpositive data in log plot"); |
6405
|
857 endif |
6512
|
858 ## FIXME -- maybe this test should also be relative? |
|
859 if (abs (min_val - max_val) < sqrt (eps)) |
|
860 min_val *= 0.9; |
|
861 max_val *= 1.1; |
6405
|
862 endif |
|
863 min_val = 10 ^ floor (log10 (min_val)); |
|
864 max_val = 10 ^ ceil (log10 (max_val)); |
|
865 else |
|
866 if (min_val == 0 && max_val == 0) |
|
867 min_val = -1; |
|
868 max_val = 1; |
6512
|
869 ## FIXME -- maybe this test should also be relative? |
|
870 elseif (abs (min_val - max_val) < sqrt (eps)) |
|
871 min_val -= 0.1 * abs (min_val); |
|
872 max_val += 0.1 * abs (max_val); |
6405
|
873 endif |
|
874 ## FIXME -- to do a better job, we should consider the tic spacing. |
|
875 scale = 10 ^ floor (log10 (max_val - min_val) - 1); |
|
876 min_val = scale * floor (min_val / scale); |
|
877 max_val = scale * ceil (max_val / scale); |
|
878 endif |
|
879 |
|
880 lim = [min_val, max_val]; |
|
881 |
|
882 endfunction |
|
883 |
6465
|
884 function [style, typ, with] = do_linestyle_command (obj, idx, plot_stream) |
6405
|
885 |
6413
|
886 persistent have_newer_gnuplot ... |
|
887 = compare_versions (__gnuplot_version__ (), "4.0", ">"); |
6405
|
888 |
|
889 if (have_newer_gnuplot) |
|
890 fprintf (plot_stream, "set style line %d default;\n", idx); |
|
891 endif |
|
892 fprintf (plot_stream, "set style line %d", idx); |
|
893 |
|
894 found_style = false; |
6425
|
895 typ = NaN; |
6465
|
896 with = ""; |
6405
|
897 |
6425
|
898 if (isfield (obj, "color")) |
6405
|
899 color = obj.color; |
|
900 if (isnumeric (color)) |
6425
|
901 if (have_newer_gnuplot) |
|
902 fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", |
|
903 round (255*color)); |
|
904 else |
|
905 if (isequal (color, [0,0,0])) |
|
906 typ = -1; |
|
907 elseif (isequal (color, [1,0,0])) |
|
908 typ = 1; |
|
909 elseif (isequal (color, [0,1,0])) |
|
910 typ = 2; |
|
911 elseif (isequal (color, [0,0,1])) |
|
912 typ = 3; |
|
913 elseif (isequal (color, [1,0,1])) |
|
914 typ = 4; |
|
915 elseif (isequal (color, [0,1,1])) |
|
916 typ = 5; |
|
917 elseif (isequal (color, [1,1,1])) |
|
918 typ = 6; |
|
919 elseif (isequal (color, [1,1,0])) |
|
920 typ = 7; |
|
921 else |
|
922 typ = 2; |
|
923 endif |
|
924 endif |
6405
|
925 endif |
|
926 found_style = true; |
|
927 endif |
|
928 |
|
929 if (isfield (obj, "linestyle")) |
|
930 switch (obj.linestyle) |
|
931 case "-" |
6415
|
932 lt = "1"; |
6405
|
933 case "--" |
6415
|
934 lt = "2"; |
6405
|
935 case ":" |
6415
|
936 lt = "3"; |
6405
|
937 case "-." |
6415
|
938 lt = "6"; |
6405
|
939 case "none" |
|
940 lt = ""; |
|
941 otherwise |
|
942 lt = ""; |
|
943 endswitch |
6843
|
944 |
|
945 ## FIXME -- linetype is currently broken, since it disables the |
|
946 ## gnuplot default dashed and solid linestyles with the only |
|
947 ## benefit of being able to specify '--' and get a single sized |
|
948 ## dashed line of identical dash pattern for all called this way. |
|
949 ## All dash patterns are a subset of "with lines" and none of the |
|
950 ## lt specifications will correctly propagate into the x11 terminal |
|
951 ## or the print command. Therefore, it is currently disabled in |
|
952 ## order to allow print (..., "-dashed") etc. to work correctly. |
|
953 |
|
954 ## if (! isempty (lt)) |
|
955 ## fprintf (plot_stream, " linetype %s", lt); |
|
956 ## found_style = true; |
|
957 ## endif |
|
958 |
6405
|
959 else |
|
960 lt = ""; |
|
961 endif |
|
962 |
|
963 if (isfield (obj, "linewidth")) |
6465
|
964 if (have_newer_gnuplot) |
|
965 fprintf (plot_stream, " linewidth %f", obj.linewidth); |
|
966 else |
|
967 with = sprintf ("%s lw %f", with, obj.linewidth); |
|
968 endif |
6405
|
969 found_style = true; |
|
970 endif |
|
971 |
|
972 if (isfield (obj, "marker")) |
|
973 switch (obj.marker) |
|
974 case "+" |
|
975 pt = "1"; |
|
976 case "o" |
6413
|
977 pt = "6"; |
6405
|
978 case "*" |
|
979 pt = "3"; |
|
980 case "." |
6413
|
981 pt = "7"; |
6405
|
982 case "x" |
|
983 pt = "2"; |
|
984 case {"square", "s"} |
|
985 pt = "5"; |
|
986 case {"diamond", "d"} |
|
987 pt = "13"; |
|
988 case "^" |
|
989 pt = "9"; |
|
990 case "v" |
|
991 pt = "11"; |
|
992 case ">" |
|
993 pt = "8"; |
|
994 case "<" |
|
995 pt = "10"; |
|
996 case {"pentagram", "p"} |
|
997 pt = "4"; |
|
998 case {"hexagram", "h"} |
6413
|
999 pt = "12"; |
6405
|
1000 case "none" |
|
1001 pt = ""; |
|
1002 otherwise |
|
1003 pt = ""; |
|
1004 endswitch |
|
1005 if (! isempty (pt)) |
6465
|
1006 if (have_newer_gnuplot) |
|
1007 fprintf (plot_stream, " pointtype %s", pt); |
|
1008 else |
|
1009 with = sprintf ("%s pt %s", with, pt); |
|
1010 endif |
6405
|
1011 found_style = true; |
|
1012 endif |
|
1013 else |
|
1014 pt = ""; |
|
1015 endif |
|
1016 |
|
1017 style = "lines"; |
|
1018 if (isempty (lt)) |
|
1019 if (! isempty (pt)) |
|
1020 style = "points"; |
|
1021 endif |
|
1022 elseif (! isempty (pt)) |
|
1023 style = "linespoints"; |
|
1024 endif |
|
1025 |
6465
|
1026 if (isfield (obj, "markersize")) |
|
1027 if (have_newer_gnuplot) |
|
1028 fprintf (plot_stream, " pointsize %f", obj.markersize); |
|
1029 else |
6758
|
1030 if (! strcmpi (style, "lines")) |
6465
|
1031 with = sprintf ("%s ps %f", with, obj.markersize); |
|
1032 endif |
|
1033 endif |
|
1034 found_style = true; |
|
1035 endif |
|
1036 |
6405
|
1037 if (have_newer_gnuplot && ! found_style) |
|
1038 fputs (plot_stream, " default"); |
|
1039 endif |
|
1040 |
|
1041 fputs (plot_stream, ";\n"); |
|
1042 |
|
1043 endfunction |
6510
|
1044 |
|
1045 function __gnuplot_write_data__ (plot_stream, data, nd, parametric) |
|
1046 |
|
1047 ## DATA is already transposed. |
|
1048 |
|
1049 ## FIXME -- this may need to be converted to C++ for speed. |
|
1050 |
6605
|
1051 ## Convert NA elements to normal NaN values because fprintf writes |
|
1052 ## "NA" and that confuses gnuplot. |
|
1053 idx = find (isna (data)); |
|
1054 if (any (idx)) |
|
1055 data(idx) = NaN; |
|
1056 endif |
|
1057 |
6510
|
1058 if (nd == 2) |
|
1059 nan_elts = find (sum (isnan (data))); |
6914
|
1060 fmt = strcat (repmat ("%.15g ", 1, rows (data)), "\n"); |
6510
|
1061 if (isempty (nan_elts)) |
|
1062 fprintf (plot_stream, fmt, data); |
|
1063 else |
|
1064 n = columns (data); |
|
1065 have_nans = true; |
|
1066 num_nan_elts = numel (nan_elts); |
|
1067 k = 1; |
|
1068 for i = 1:n |
|
1069 if (have_nans && i == nan_elts(k)) |
|
1070 fputs (plot_stream, "\n"); |
|
1071 have_nans = ++k <= num_nan_elts; |
|
1072 else |
|
1073 fprintf (plot_stream, fmt, data(:,i)); |
|
1074 endif |
|
1075 endfor |
|
1076 endif |
|
1077 else |
|
1078 ## FIXME -- handle NaNs here too? |
|
1079 if (parametric) |
6914
|
1080 fprintf (plot_stream, "%.15g %.15g %.15g\n", data); |
6510
|
1081 else |
|
1082 nc = columns (data); |
|
1083 for j = 1:3:nc |
6914
|
1084 fprintf (plot_stream, "%.15g %.15g %.15g\n", data(:,j:j+2)'); |
6510
|
1085 fputs (plot_stream, "\n"); |
|
1086 endfor |
|
1087 endif |
|
1088 endif |
|
1089 fputs (plot_stream, "e\n"); |
|
1090 |
|
1091 endfunction |
6745
|
1092 |
|
1093 function do_tics (obj, plot_stream) |
6809
|
1094 if (strcmpi (obj.xaxislocation, "top")) |
|
1095 do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, |
|
1096 "x2", plot_stream); |
|
1097 do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, |
|
1098 "x", plot_stream); |
|
1099 else |
|
1100 do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, |
|
1101 "x", plot_stream); |
|
1102 do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, |
|
1103 "x2", plot_stream); |
|
1104 endif |
|
1105 if (strcmpi (obj.yaxislocation, "right")) |
|
1106 do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, |
|
1107 "y2", plot_stream); |
|
1108 do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, |
|
1109 "y", plot_stream); |
|
1110 else |
|
1111 do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, |
|
1112 "y", plot_stream); |
|
1113 do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, |
|
1114 "y2", plot_stream); |
|
1115 endif |
6745
|
1116 do_tics_1 (obj.ztickmode, obj.ztick, obj.zticklabelmode, obj.zticklabel, |
|
1117 "z", plot_stream); |
|
1118 endfunction |
|
1119 |
|
1120 function do_tics_1 (ticmode, tics, labelmode, labels, ax, plot_stream) |
6758
|
1121 if (strcmpi (ticmode, "manual")) |
6745
|
1122 if (isempty (tics)) |
|
1123 fprintf (plot_stream, "unset %stics;\n", ax); |
6758
|
1124 elseif (strcmpi (labelmode, "manual") && ! isempty (labels)) |
6751
|
1125 if (ischar (labels)) |
|
1126 labels = cellstr (labels); |
|
1127 endif |
6745
|
1128 if (iscellstr (labels)) |
6751
|
1129 k = 1; |
|
1130 ntics = numel (tics); |
|
1131 nlabels = numel (labels); |
6745
|
1132 fprintf (plot_stream, "set format %s \"%%s\";\n", ax); |
|
1133 fprintf (plot_stream, "set %stics (", ax); |
|
1134 for i = 1:ntics |
6920
|
1135 fprintf (plot_stream, " \"%s\" %g", labels(k++), tics(i)) |
6745
|
1136 if (i < ntics) |
|
1137 fputs (plot_stream, ", "); |
|
1138 endif |
|
1139 if (k > nlabels) |
|
1140 k = 1; |
|
1141 endif |
|
1142 endfor |
|
1143 fputs (plot_stream, ");\n"); |
|
1144 else |
|
1145 error ("unsupported type of ticklabel"); |
|
1146 endif |
|
1147 else |
6920
|
1148 fprintf (plot_stream, "set format %s \"%%g\";\n", ax); |
6745
|
1149 fprintf (plot_stream, "set %stics (", ax); |
6920
|
1150 fprintf (plot_stream, " %g,", tics(1:end-1)); |
|
1151 fprintf (plot_stream, " %g);\n", tics(end)); |
6745
|
1152 endif |
|
1153 else |
6920
|
1154 fprintf (plot_stream, "set format %s \"%%g\";\n", ax); |
6745
|
1155 fprintf (plot_stream, "set %stics;\n", ax); |
|
1156 endif |
|
1157 endfunction |