7017
|
1 ## Copyright (C) 2005, 2007 John W. Eaton |
6405
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
6405
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
6405
|
18 |
6895
|
19 ## Undocumented internal function. |
6405
|
20 |
|
21 ## Author: jwe |
|
22 |
7189
|
23 function __go_draw_axes__ (h, plot_stream, enhanced) |
6405
|
24 |
7189
|
25 if (nargin == 3) |
6405
|
26 |
|
27 axis_obj = get (h); |
|
28 |
|
29 parent_figure_obj = get (axis_obj.parent); |
|
30 |
6413
|
31 persistent have_newer_gnuplot ... |
|
32 = compare_versions (__gnuplot_version__ (), "4.0", ">"); |
6405
|
33 |
|
34 ## Set axis properties here? |
7189
|
35 pos = [0,0,1,1]; |
6405
|
36 if (! isempty (axis_obj.outerposition)) |
|
37 pos = axis_obj.outerposition; |
|
38 endif |
|
39 |
|
40 if (! isempty (axis_obj.position)) |
|
41 pos = axis_obj.position; |
|
42 endif |
|
43 |
7189
|
44 if (! strcmp (axis_obj.__colorbar__, "none")) |
|
45 [pos, cbox_orient, cbox_size, cbox_origin, cbox_mirror] = ... |
|
46 gnuplot_postion_colorbox (pos, axis_obj.__colorbar__); |
|
47 endif |
|
48 |
|
49 fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2)); |
|
50 fprintf (plot_stream, "set size %.15g, %.15g;\n", pos(3), pos(4)); |
|
51 |
6758
|
52 if (strcmpi (axis_obj.dataaspectratiomode, "manual")) |
6405
|
53 r = axis_obj.dataaspectratio; |
6914
|
54 fprintf (plot_stream, "set size ratio %.15g;\n", -r(2)/r(1)); |
6405
|
55 else |
|
56 fputs (plot_stream, "set size noratio;\n"); |
|
57 endif |
|
58 |
7189
|
59 fputs (plot_stream, "set pm3d;\n"); |
6778
|
60 fputs (plot_stream, "unset label;\n"); |
|
61 |
6405
|
62 if (! isempty (axis_obj.title)) |
|
63 t = get (axis_obj.title); |
|
64 if (isempty (t.string)) |
|
65 fputs (plot_stream, "unset title;\n"); |
|
66 else |
7189
|
67 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", |
|
68 have_newer_gnuplot); |
7162
|
69 fprintf (plot_stream, "set title \"%s\" font \"%s,%d\";\n", |
7189
|
70 undo_string_escapes (tt), f, s); |
6405
|
71 endif |
|
72 endif |
|
73 |
|
74 if (! isempty (axis_obj.xlabel)) |
|
75 t = get (axis_obj.xlabel); |
6737
|
76 angle = t.rotation; |
6405
|
77 if (isempty (t.string)) |
|
78 fputs (plot_stream, "unset xlabel;\n"); |
|
79 else |
7189
|
80 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", |
|
81 have_newer_gnuplot); |
7162
|
82 fprintf (plot_stream, "set xlabel \"%s\" font \"%s,%d\"", |
7189
|
83 undo_string_escapes (tt), f, s); |
6738
|
84 if (have_newer_gnuplot) |
|
85 ## Rotation of xlabel not yet support by gnuplot as of 4.2, but |
|
86 ## there is no message about it. |
|
87 fprintf (plot_stream, " rotate by %f", angle); |
|
88 endif |
|
89 fputs (plot_stream, ";\n"); |
6405
|
90 endif |
|
91 endif |
|
92 |
|
93 if (! isempty (axis_obj.ylabel)) |
|
94 t = get (axis_obj.ylabel); |
6737
|
95 angle = t.rotation; |
6405
|
96 if (isempty (t.string)) |
|
97 fputs (plot_stream, "unset ylabel;\n"); |
|
98 else |
7189
|
99 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", |
|
100 have_newer_gnuplot); |
7162
|
101 fprintf (plot_stream, "set ylabel \"%s\" font \"%s,%d\"", |
7189
|
102 undo_string_escapes (tt), f, s); |
6738
|
103 if (have_newer_gnuplot) |
6766
|
104 fprintf (plot_stream, " rotate by %f;\n", angle); |
6738
|
105 endif |
|
106 fputs (plot_stream, ";\n"); |
6405
|
107 endif |
|
108 endif |
|
109 |
|
110 if (! isempty (axis_obj.zlabel)) |
|
111 t = get (axis_obj.zlabel); |
6737
|
112 angle = t.rotation; |
6405
|
113 if (isempty (t.string)) |
|
114 fputs (plot_stream, "unset zlabel;\n"); |
|
115 else |
7189
|
116 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", |
|
117 have_newer_gnuplot); |
|
118 fprintf (plot_stream, "set zlabel \"%s\" font \"%s,%d\"", |
|
119 undo_string_escapes (tt), f, s); |
6738
|
120 if (have_newer_gnuplot) |
|
121 ## Rotation of zlabel not yet support by gnuplot as of 4.2, but |
|
122 ## there is no message about it. |
|
123 fprintf (plot_stream, " rotate by %f;\n", angle); |
|
124 endif |
|
125 fputs (plot_stream, ";\n"); |
6405
|
126 endif |
|
127 endif |
|
128 |
6809
|
129 if (strcmpi (axis_obj.xaxislocation, "top")) |
|
130 xaxisloc = "x2"; |
|
131 xaxisloc_using = "x2"; |
|
132 else |
|
133 xaxisloc = "x"; |
|
134 xaxisloc_using = "x1"; |
|
135 endif |
|
136 if (strcmpi (axis_obj.yaxislocation, "right")) |
|
137 yaxisloc = "y2"; |
|
138 yaxisloc_using = "y2"; |
|
139 else |
|
140 yaxisloc = "y"; |
|
141 yaxisloc_using = "y1"; |
|
142 endif |
|
143 |
6758
|
144 if (strcmpi (axis_obj.xgrid, "on")) |
6809
|
145 fprintf (plot_stream, "set grid %stics;\n", xaxisloc); |
6405
|
146 else |
6809
|
147 fprintf (plot_stream, "set grid no%stics;\n", xaxisloc); |
6405
|
148 endif |
|
149 |
6758
|
150 if (strcmpi (axis_obj.ygrid, "on")) |
6809
|
151 fprintf (plot_stream, "set grid %stics;\n", yaxisloc); |
6405
|
152 else |
6809
|
153 fprintf (plot_stream, "set grid no%stics;\n", yaxisloc); |
6405
|
154 endif |
|
155 |
6758
|
156 if (strcmpi (axis_obj.zgrid, "on")) |
6405
|
157 fputs (plot_stream, "set grid ztics;\n"); |
|
158 else |
7085
|
159 fputs (plot_stream, "set grid noztics;\n"); |
6405
|
160 endif |
|
161 |
6758
|
162 if (strcmpi (axis_obj.xminorgrid, "on")) |
6809
|
163 fprintf (plot_stream, "set m%stics 5;\n", xaxisloc); |
|
164 fprintf (plot_stream, "set grid m%stics;\n", xaxisloc); |
6405
|
165 else |
6809
|
166 fprintf (plot_stream, "set grid nom%stics;\n", xaxisloc); |
6405
|
167 endif |
|
168 |
6758
|
169 if (strcmpi (axis_obj.yminorgrid, "on")) |
6809
|
170 fprintf (plot_stream, "set m%stics 5;\n", yaxisloc); |
|
171 fprintf (plot_stream, "set grid m%stics;\n", yaxisloc); |
6405
|
172 else |
6809
|
173 fprintf (plot_stream, "set grid nom%stics;\n", yaxisloc); |
6405
|
174 endif |
|
175 |
6758
|
176 if (strcmpi (axis_obj.zminorgrid, "on")) |
6405
|
177 fputs (plot_stream, "set mztics 5;\n"); |
|
178 fputs (plot_stream, "set grid mztics;\n"); |
|
179 else |
|
180 fputs (plot_stream, "set grid nomztics;\n"); |
|
181 endif |
|
182 |
6745
|
183 do_tics (axis_obj, plot_stream); |
6405
|
184 |
6758
|
185 xlogscale = strcmpi (axis_obj.xscale, "log"); |
6405
|
186 if (xlogscale) |
6809
|
187 fprintf (plot_stream, "set logscale %s;\n", xaxisloc); |
6405
|
188 else |
6809
|
189 fprintf (plot_stream, "unset logscale %s;\n", xaxisloc); |
6405
|
190 endif |
|
191 |
6758
|
192 ylogscale = strcmpi (axis_obj.yscale, "log"); |
6405
|
193 if (ylogscale) |
6809
|
194 fprintf (plot_stream, "set logscale %s;\n", yaxisloc); |
6405
|
195 else |
6809
|
196 fprintf (plot_stream, "unset logscale %s;\n", yaxisloc); |
6405
|
197 endif |
|
198 |
6758
|
199 zlogscale = strcmpi (axis_obj.zscale, "log"); |
6405
|
200 if (zlogscale) |
|
201 fputs (plot_stream, "set logscale z;\n"); |
|
202 else |
|
203 fputs (plot_stream, "unset logscale z;\n"); |
|
204 endif |
|
205 |
6758
|
206 xautoscale = strcmpi (axis_obj.xlimmode, "auto"); |
|
207 yautoscale = strcmpi (axis_obj.ylimmode, "auto"); |
|
208 zautoscale = strcmpi (axis_obj.zlimmode, "auto"); |
7109
|
209 cautoscale = strcmpi (axis_obj.climmode, "auto"); |
6405
|
210 |
|
211 kids = axis_obj.children; |
|
212 |
|
213 nd = 0; |
|
214 data_idx = 0; |
|
215 data = cell (); |
6464
|
216 is_image_data = []; |
7175
|
217 hidden_removal = NaN; |
6405
|
218 |
7109
|
219 xminp = yminp = zminp = cminp = Inf; |
|
220 xmax = ymax = zmax = cmax = -Inf; |
|
221 xmin = ymin = zmin = cmin = Inf; |
6405
|
222 |
7189
|
223 ## This has to be done here as some of the code below depends on the |
|
224 ## final clim |
|
225 if (cautoscale) |
|
226 for i = 1:length (kids) |
|
227 obj = get (kids(i)); |
|
228 if (isfield (obj, "cdata")) |
|
229 [cmin, cmax, cminp] = get_data_limits (cmin, cmax, cminp, |
|
230 obj.cdata(:)); |
|
231 endif |
|
232 endfor |
|
233 if (cmin == cmax) |
|
234 cmax = cmin + 1; |
|
235 endif |
|
236 clim = [cmin, cmax]; |
|
237 else |
|
238 clim = axis_obj.clim; |
|
239 if (clim(1) == clim(2)) |
|
240 clim = [clim(1), clim(1) + 1]; |
|
241 endif |
|
242 endif |
|
243 |
6405
|
244 [view_cmd, view_fcn, view_zoom] = image_viewer (); |
|
245 use_gnuplot_for_images = (ischar (view_fcn) |
|
246 && strcmp (view_fcn, "gnuplot_internal")); |
|
247 |
|
248 ximg_data = {}; |
|
249 ximg_data_idx = 0; |
|
250 |
|
251 for i = 1:length (kids) |
|
252 |
|
253 obj = get (kids(i)); |
|
254 |
|
255 switch (obj.type) |
|
256 case "image" |
|
257 ## FIXME - Is there a better way to determine if the plot |
|
258 ## command should be "plot" or "splot"????? Could have images |
|
259 ## projected into 3D so there is really no reason to limit |
|
260 ## this. |
|
261 if (nd == 0) |
|
262 nd = 2; |
|
263 endif |
|
264 |
|
265 img_data = obj.cdata; |
|
266 img_xdata = obj.xdata; |
|
267 img_ydata = obj.ydata; |
|
268 |
|
269 if (use_gnuplot_for_images) |
|
270 |
|
271 data_idx++; |
6464
|
272 is_image_data(data_idx) = true; |
6861
|
273 parametric(data_idx) = false; |
7119
|
274 have_cdata(data_idx) = false; |
6405
|
275 |
|
276 [y_dim, x_dim] = size (img_data(:,:,1)); |
|
277 if (x_dim > 1) |
|
278 dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1); |
|
279 else |
|
280 dx = 1; |
|
281 endif |
|
282 if (y_dim > 1) |
|
283 dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1); |
|
284 else |
|
285 dy = 1; |
|
286 endif |
|
287 x_origin = min (img_xdata); |
|
288 y_origin = min (img_ydata); |
|
289 |
|
290 if (nd == 2) |
|
291 if (xautoscale) |
|
292 xmin = min (xmin, min (img_xdata) - dx/2); |
|
293 xmax = max (xmax, max (img_xdata) + dx/2); |
|
294 xminp = min (xminp, min (img_xdata((img_xdata - dx/2)>0)) - dx/2); |
|
295 endif |
|
296 if (yautoscale) |
|
297 ymin = min (ymin, min (img_ydata) - dy/2); |
|
298 ymax = max (ymax, max (img_ydata) + dy/2); |
|
299 yminp = min (yminp, min (img_ydata((img_ydata - dy/2)>0)) - dy/2); |
|
300 endif |
|
301 else |
|
302 ## Can have images in 3D, but the image routines don't seem |
|
303 ## to have a means of arbitrary projection. |
|
304 endif |
|
305 |
|
306 if (ndims (img_data) == 3) |
6464
|
307 data{data_idx} = permute (img_data, [3, 1, 2])(:); |
6405
|
308 format = "1:2:3"; |
|
309 imagetype = "rgbimage"; |
|
310 else |
6464
|
311 data{data_idx} = img_data(:); |
6405
|
312 format = "1"; |
|
313 imagetype = "image"; |
|
314 endif |
|
315 |
6579
|
316 titlespec{data_idx} = "title \"\""; |
6914
|
317 usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx origin=(%.15g,%.15g) dx=%.15g dy=%.15g using %s", |
6405
|
318 x_dim, y_dim, x_origin, y_origin, dx, dy, format); |
|
319 withclause{data_idx} = sprintf ("with %s", imagetype); |
|
320 |
|
321 else |
|
322 ximg_data{++ximg_data_idx} = img_data; |
|
323 endif |
|
324 |
|
325 case "line" |
7120
|
326 if (strncmp (obj.linestyle, "none", 4) |
|
327 && (! isfield (obj, "marker") |
|
328 || (isfield (obj, "marker") |
|
329 && strncmp (obj.marker, "none", 4)))) |
|
330 continue; |
|
331 endif |
6405
|
332 data_idx++; |
6464
|
333 is_image_data(data_idx) = false; |
6861
|
334 parametric(data_idx) = true; |
7119
|
335 have_cdata(data_idx) = false; |
6405
|
336 if (isempty (obj.keylabel)) |
|
337 titlespec{data_idx} = "title \"\""; |
|
338 else |
7189
|
339 tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "keylabel", have_newer_gnuplot)); |
7094
|
340 titlespec{data_idx} = strcat ("title \"", tmp, "\""); |
6405
|
341 endif |
6465
|
342 [style, typ, with] = do_linestyle_command (obj, data_idx, plot_stream); |
6405
|
343 usingclause{data_idx} = ""; |
6425
|
344 if (have_newer_gnuplot || isnan (typ)) |
|
345 withclause{data_idx} = sprintf ("with %s linestyle %d", |
|
346 style, data_idx); |
|
347 else |
|
348 withclause{data_idx} = sprintf ("with %s linetype %d", |
|
349 style, typ); |
|
350 endif |
6405
|
351 if (! isempty (obj.zdata)) |
|
352 nd = 3; |
|
353 xdat = obj.xdata(:); |
|
354 ydat = obj.ydata(:); |
|
355 zdat = obj.zdata(:); |
7119
|
356 |
6405
|
357 if (xautoscale) |
6453
|
358 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat); |
6405
|
359 endif |
|
360 if (yautoscale) |
6453
|
361 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat); |
6405
|
362 endif |
|
363 if (zautoscale) |
6453
|
364 [zmin, zmax, zminp] = get_data_limits (zmin, zmax, zminp, zdat); |
6405
|
365 endif |
|
366 data{data_idx} = [xdat, ydat, zdat]'; |
|
367 usingclause{data_idx} = "using ($1):($2):($3)"; |
|
368 fputs (plot_stream, "set parametric;\n"); |
|
369 fputs (plot_stream, "set style data lines;\n"); |
|
370 fputs (plot_stream, "set surface;\n"); |
|
371 fputs (plot_stream, "unset contour;\n"); |
|
372 else |
|
373 nd = 2; |
|
374 xdat = obj.xdata(:); |
|
375 ydat = obj.ydata(:); |
|
376 ldat = obj.ldata; |
|
377 yerr = xerr = false; |
|
378 if (! isempty (ldat)) |
|
379 yerr = true; |
|
380 ldat = ldat(:); |
|
381 endif |
|
382 udat = obj.udata; |
|
383 if (! isempty (udat)) |
|
384 udat = udat(:); |
|
385 endif |
|
386 xldat = obj.xldata; |
|
387 if (! isempty (xldat)) |
|
388 xerr = true; |
|
389 xldat = xldat(:); |
|
390 endif |
|
391 xudat = obj.xudata; |
|
392 if (! isempty (xudat)) |
|
393 xudat = xudat(:); |
|
394 endif |
|
395 if (yerr) |
|
396 ylo = ydat-ldat; |
|
397 yhi = ydat+udat; |
|
398 if (yautoscale) |
|
399 ty = [ydat; ylo; yhi]; |
6453
|
400 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ty); |
6405
|
401 endif |
|
402 if (xerr) |
|
403 xlo = xdat-xldat; |
|
404 xhi = xdat+xudat; |
|
405 if (xautoscale) |
|
406 tx = [xdat; xlo; xhi]; |
6453
|
407 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, tx); |
6405
|
408 endif |
|
409 data{data_idx} = [xdat, ydat, xlo, xhi, ylo, yhi]'; |
|
410 usingclause{data_idx} = "using ($1):($2):($3):($4):($5):($6)"; |
6908
|
411 withclause{data_idx} = "with xyerrorbars"; |
6405
|
412 else |
6736
|
413 ## Obtain the limits based on the exact x values. |
6405
|
414 if (xautoscale) |
6453
|
415 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, |
6736
|
416 xminp, xdat); |
6405
|
417 endif |
|
418 data{data_idx} = [xdat, ydat, ylo, yhi]'; |
|
419 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
6908
|
420 withclause{data_idx} = "with yerrorbars"; |
6405
|
421 endif |
|
422 elseif (xerr) |
|
423 xlo = xdat-xldat; |
|
424 xhi = xdat+xudat; |
|
425 if (xautoscale) |
|
426 tx = [xdat; xlo; xhi]; |
6453
|
427 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, tx); |
6405
|
428 endif |
|
429 if (yautoscale) |
6453
|
430 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, |
|
431 yminp, ydat, ty); |
6405
|
432 endif |
|
433 data{data_idx} = [xdat, ydat, xlo, xhi]'; |
|
434 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
6908
|
435 withclause{data_idx} = "with xerrorbars"; |
6405
|
436 else |
|
437 if (xautoscale) |
6453
|
438 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat); |
6405
|
439 endif |
|
440 if (yautoscale) |
6453
|
441 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat); |
6405
|
442 endif |
|
443 data{data_idx} = [xdat, ydat]'; |
6809
|
444 usingclause{data_idx} = sprintf ("using ($1):($2) axes %s%s", |
|
445 xaxisloc_using, yaxisloc_using); |
6405
|
446 endif |
|
447 endif |
6465
|
448 if (! (have_newer_gnuplot || isempty (with))) |
|
449 if (isempty (withclause{data_idx})) |
6809
|
450 withclause{data_idx} = sprintf ("with %s", with); |
6465
|
451 else |
6809
|
452 withclause{data_idx} = sprintf ("%s %s", withclause{data_idx}, |
|
453 with); |
6465
|
454 endif |
|
455 endif |
6405
|
456 |
6790
|
457 case "patch" |
6885
|
458 cmap = parent_figure_obj.colormap; |
7020
|
459 [nr, nc] = size (obj.xdata); |
|
460 |
7189
|
461 if (! isempty (obj.cdata)) |
|
462 cdat = obj.cdata; |
|
463 else |
|
464 cdat = []; |
|
465 endif |
|
466 |
7170
|
467 for i = 1:nc |
7020
|
468 xcol = obj.xdata(:,i); |
|
469 ycol = obj.ydata(:,i); |
7170
|
470 if (! isempty (obj.zdata)) |
|
471 zcol = obj.zdata(:,i); |
|
472 else |
|
473 zcol = []; |
|
474 endif |
7020
|
475 |
|
476 if (xautoscale) |
|
477 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xcol); |
|
478 endif |
|
479 if (yautoscale) |
|
480 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ycol); |
|
481 endif |
7170
|
482 if (! isempty (obj.zdata) && ! strncmp(obj.edgecolor, "none", 4)) |
|
483 if (zautoscale) |
|
484 [zmin, zmax, zminp] = get_data_limits (zmin, zmax, zminp, zcol); |
|
485 endif |
|
486 endif |
7020
|
487 |
|
488 if (! isnan (xcol) && ! isnan (ycol)) |
|
489 ## Is the patch closed or not |
7175
|
490 if (strncmp (obj.facecolor, "none", 4)) |
|
491 if (isnan (hidden_removal)) |
|
492 hidden_removal = false; |
|
493 endif |
|
494 else |
|
495 hidden_removal = true; |
7170
|
496 if (! isempty (zcol)) |
|
497 error ("gnuplot (as of v4.2) only supports 2D filled patches"); |
|
498 else |
|
499 nd = 2; |
|
500 endif |
|
501 |
|
502 data_idx++; |
|
503 is_image_data(data_idx) = false; |
|
504 parametric(data_idx) = false; |
|
505 have_cdata(data_idx) = false; |
|
506 if (i > 1 || isempty (obj.keylabel)) |
|
507 titlespec{data_idx} = "title \"\""; |
|
508 else |
7189
|
509 tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "keylabel", have_newer_gnuplot)); |
7170
|
510 titlespec{data_idx} = strcat ("title \"", tmp, "\""); |
|
511 endif |
|
512 usingclause{data_idx} = ""; |
7189
|
513 if (isfield (obj, "facecolor")) |
|
514 if ((strncmp (obj.facecolor, "flat", 4) |
|
515 || strncmp (obj.facecolor, "interp", 6)) && |
|
516 isfield (obj, "cdata")) |
7170
|
517 if (ndims (obj.cdata) == 2 |
7189
|
518 && (size (obj.cdata, 2) == nc |
|
519 && (size (obj.cdata, 1) == 1 |
|
520 || size (obj.cdata, 1) == 3))) |
|
521 ccol = cdat (:, i); |
|
522 elseif (ndims (obj.cdata) == 2 |
|
523 && (size (obj.cdata, 1) == nc |
|
524 && (size (obj.cdata, 2) == 1 |
|
525 || size (obj.cdata, 2) == 3))) |
|
526 ccol = cdat (i, :); |
7170
|
527 elseif (ndims (obj.cdata) == 3) |
7189
|
528 ccol = permute (cdat (:, i, :), [1, 3, 2]); |
7170
|
529 else |
7189
|
530 ccol = cdat; |
7170
|
531 endif |
|
532 if (strncmp (obj.facecolor, "flat", 4)) |
|
533 if (numel(ccol) == 3) |
|
534 color = ccol; |
|
535 else |
7189
|
536 if (cautoscale) |
|
537 r = 1 + round ((size (cmap, 1) - 1) |
|
538 * (ccol - cmin)/(cmax - cmin)); |
|
539 else |
|
540 r = 1 + round ((size (cmap, 1) - 1) |
|
541 * (ccol - clim(1))/(clim(2) - clim(1))); |
|
542 endif |
7170
|
543 r = max (1, min (r, size (cmap, 1))); |
|
544 color = cmap(r, :); |
|
545 endif |
|
546 elseif (strncmp (obj.facecolor, "interp", 6)) |
|
547 warning ("\"interp\" not supported, using 1st entry of cdata") |
|
548 r = 1 + round ((size (cmap, 1) - 1) * ccol(1)); |
|
549 r = max (1, min (r, size (cmap, 1))); |
|
550 color = cmap(r,:); |
|
551 endif |
7189
|
552 elseif (isnumeric (obj.facecolor)) |
|
553 color = obj.facecolor; |
7170
|
554 else |
7189
|
555 color = [0, 1, 0]; |
7170
|
556 endif |
|
557 else |
|
558 color = [0, 1, 0]; |
|
559 endif |
|
560 |
|
561 if (have_newer_gnuplot) |
|
562 withclause{data_idx} ... |
|
563 = sprintf ("with filledcurve lc rgb \"#%02x%02x%02x\"", |
|
564 round (255*color)); |
|
565 else |
|
566 if (isequal (color, [0,0,0])) |
|
567 typ = -1; |
|
568 elseif (isequal (color, [1,0,0])) |
|
569 typ = 1; |
|
570 elseif (isequal (color, [0,1,0])) |
|
571 typ = 2; |
|
572 elseif (isequal (color, [0,0,1])) |
|
573 typ = 3; |
|
574 elseif (isequal (color, [1,0,1])) |
|
575 typ = 4; |
|
576 elseif (isequal (color, [0,1,1])) |
|
577 typ = 5; |
|
578 elseif (isequal (color, [1,1,1])) |
|
579 typ = -1; |
|
580 elseif (isequal (color, [1,1,0])) |
|
581 typ = 7; |
|
582 else |
|
583 typ = -1; |
|
584 endif |
|
585 withclause{data_idx} = sprintf ("with filledcurve lt %d", typ); |
|
586 endif |
|
587 data{data_idx} = [xcol, ycol]'; |
|
588 usingclause{data_idx} = "using ($1):($2)"; |
|
589 endif |
|
590 endif |
|
591 |
|
592 ## patch outline |
|
593 if (! strncmp (obj.edgecolor, "none", 4)) |
|
594 if (! isempty (zcol)) |
|
595 nd = 3; |
7148
|
596 else |
7170
|
597 nd = 2; |
7148
|
598 endif |
7170
|
599 |
|
600 data_idx++; |
|
601 is_image_data(data_idx) = false; |
|
602 parametric(data_idx) = false; |
|
603 have_cdata(data_idx) = false; |
|
604 titlespec{data_idx} = "title \"\""; |
7020
|
605 usingclause{data_idx} = ""; |
7189
|
606 |
|
607 if (isfield (obj, "markersize")) |
|
608 mdat = obj.markersize; |
|
609 endif |
|
610 |
|
611 if (isfield (obj, "edgecolor")) |
|
612 if ((strncmp (obj.edgecolor, "flat", 4) |
|
613 || strncmp (obj.edgecolor, "interp", 6)) && |
|
614 isfield (obj, "cdata")) |
7119
|
615 if (ndims (obj.cdata) == 2 |
7189
|
616 && (size (obj.cdata, 2) == nc |
|
617 && (size (obj.cdata, 1) == 1 |
|
618 || size (obj.cdata, 1) == 3))) |
|
619 ccol = cdat (:, i); |
|
620 elseif (ndims (obj.cdata) == 2 |
|
621 && (size (obj.cdata, 1) == nc |
|
622 && (size (obj.cdata, 2) == 1 |
|
623 || size (obj.cdata, 2) == 3))) |
|
624 ccol = cdat (i, :); |
7020
|
625 elseif (ndims (obj.cdata) == 3) |
7189
|
626 ccol = permute (cdat (:, i, :), [1, 3, 2]); |
7020
|
627 else |
7189
|
628 ccol = cdat; |
7020
|
629 endif |
7170
|
630 if (strncmp (obj.edgecolor, "flat", 4)) |
7189
|
631 if (numel(ccol) == 3) |
7020
|
632 color = ccol; |
|
633 else |
7189
|
634 if (cautoscale) |
|
635 r = 1 + round ((size (cmap, 1) - 1) |
|
636 * (ccol - cmin)/(cmax - cmin)); |
|
637 else |
|
638 r = 1 + round ((size (cmap, 1) - 1) |
|
639 * (ccol - clim(1))/(clim(2) - clim(1))); |
|
640 endif |
7020
|
641 r = max (1, min (r, size (cmap, 1))); |
|
642 color = cmap(r, :); |
|
643 endif |
7170
|
644 elseif (strncmp (obj.edgecolor, "interp", 6)) |
7020
|
645 warning ("\"interp\" not supported, using 1st entry of cdata") |
|
646 r = 1 + round ((size (cmap, 1) - 1) * ccol(1)); |
|
647 r = max (1, min (r, size (cmap, 1))); |
|
648 color = cmap(r,:); |
|
649 endif |
7189
|
650 elseif (isnumeric (obj.edgecolor)) |
|
651 color = obj.edgecolor; |
|
652 else |
|
653 color = [0, 0, 0]; |
7020
|
654 endif |
|
655 else |
7189
|
656 color = [0, 0, 0]; |
7020
|
657 endif |
7189
|
658 |
|
659 if (isfield (obj, "linestyle")) |
|
660 switch (obj.linestyle) |
|
661 case "-" |
|
662 lt = "1"; |
|
663 case "--" |
|
664 lt = "2"; |
|
665 case ":" |
|
666 lt = "3"; |
|
667 case "-." |
|
668 lt = "6"; |
|
669 case "none" |
|
670 lt = ""; |
|
671 otherwise |
|
672 lt = ""; |
|
673 endswitch |
|
674 else |
|
675 lt = ""; |
|
676 endif |
|
677 |
|
678 if (isfield (obj, "marker")) |
|
679 if (isfield (obj, "marker")) |
|
680 switch (obj.marker) |
|
681 case "+" |
|
682 pt = "pt 1"; |
|
683 case "o" |
|
684 pt = "pt 6"; |
|
685 case "*" |
|
686 pt = "pt 3"; |
|
687 case "." |
|
688 pt = "pt 0"; |
|
689 case "x" |
|
690 pt = "pt 2"; |
|
691 case {"square", "s"} |
|
692 pt = "pt 5"; |
|
693 case {"diamond", "d"} |
|
694 pt = "pt 13"; |
|
695 case "^" |
|
696 pt = "pt 9"; |
|
697 case "v" |
|
698 pt = "pt 11"; |
|
699 case ">" |
|
700 pt = "pt 8"; |
|
701 case "<" |
|
702 pt = "pt 10"; |
|
703 case {"pentagram", "p"} |
|
704 pt = "pt 4"; |
|
705 case {"hexagram", "h"} |
|
706 pt = "pt 12"; |
|
707 case "none" |
|
708 pt = ""; |
|
709 otherwise |
|
710 pt = ""; |
|
711 endswitch |
|
712 endif |
|
713 else |
|
714 pt = ""; |
|
715 endif |
|
716 |
|
717 style = "lines"; |
|
718 if (isempty (lt)) |
|
719 if (! isempty (pt)) |
|
720 style = "points"; |
|
721 endif |
|
722 elseif (! isempty (pt)) |
|
723 style = "linespoints"; |
|
724 endif |
|
725 |
|
726 if (isfield (obj, "markersize")) |
|
727 if (length (mdat) == nc) |
|
728 m = mdat(i); |
|
729 else |
|
730 m = mdat; |
|
731 endif |
|
732 if (! strcmpi (style, "lines")) |
|
733 if (have_newer_gnuplot) |
|
734 ps = sprintf("pointsize %f", m); |
|
735 else |
|
736 ps = sprintf("ps %f", m); |
|
737 endif |
|
738 else |
|
739 ps = ""; |
|
740 endif |
|
741 else |
|
742 ps = ""; |
|
743 endif |
|
744 |
7020
|
745 if (have_newer_gnuplot) |
7119
|
746 withclause{data_idx} ... |
7189
|
747 = sprintf ("with %s %s %s lc rgb \"#%02x%02x%02x\"", |
|
748 style, pt, ps, round (255*color)); |
7020
|
749 else |
|
750 if (isequal (color, [0,0,0])) |
|
751 typ = -1; |
|
752 elseif (isequal (color, [1,0,0])) |
|
753 typ = 1; |
|
754 elseif (isequal (color, [0,1,0])) |
|
755 typ = 2; |
|
756 elseif (isequal (color, [0,0,1])) |
|
757 typ = 3; |
|
758 elseif (isequal (color, [1,0,1])) |
|
759 typ = 4; |
|
760 elseif (isequal (color, [0,1,1])) |
|
761 typ = 5; |
|
762 elseif (isequal (color, [1,1,1])) |
|
763 typ = -1; |
|
764 elseif (isequal (color, [1,1,0])) |
|
765 typ = 7; |
|
766 else |
|
767 typ = -1; |
|
768 endif |
7189
|
769 withclause{data_idx} = sprintf ("with %s %s %s lt %d", |
|
770 style, pt, ps, typ); |
7020
|
771 endif |
6790
|
772 |
7170
|
773 if (! isempty (zcol)) |
|
774 if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol)) |
|
775 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ... |
|
776 [zcol; zcol(1)]]'; |
|
777 else |
|
778 data{data_idx} = [xcol, ycol, zcol]'; |
|
779 endif |
|
780 usingclause{data_idx} = "using ($1):($2):($3)"; |
7020
|
781 else |
7170
|
782 if (! isnan (xcol) && ! isnan (ycol)) |
|
783 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]'; |
|
784 else |
|
785 data{data_idx} = [xcol, ycol]'; |
|
786 endif |
|
787 usingclause{data_idx} = "using ($1):($2)"; |
7020
|
788 endif |
6885
|
789 endif |
7020
|
790 endfor |
6790
|
791 |
6405
|
792 case "surface" |
7119
|
793 nd = 3; |
7110
|
794 if (! (strncmp (obj.edgecolor, "none", 4) |
|
795 && strncmp (obj.facecolor, "none", 4))) |
7109
|
796 data_idx++; |
|
797 is_image_data(data_idx) = false; |
|
798 parametric(data_idx) = false; |
7119
|
799 have_cdata(data_idx) = true; |
7170
|
800 [style, typ, with] = do_linestyle_command (obj, data_idx, |
|
801 plot_stream); |
7109
|
802 if (isempty (obj.keylabel)) |
|
803 titlespec{data_idx} = "title \"\""; |
|
804 else |
7189
|
805 tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "keylabel", have_newer_gnuplot)); |
7109
|
806 titlespec{data_idx} = strcat ("title \"", tmp, "\""); |
|
807 endif |
|
808 usingclause{data_idx} = ""; |
|
809 if (have_newer_gnuplot || isnan (typ)) |
|
810 withclause{data_idx} = sprintf ("with %s linestyle %d", |
|
811 style, data_idx); |
6405
|
812 else |
7109
|
813 withclause{data_idx} = sprintf ("with %s linetype %d %s", |
|
814 style, typ, with); |
|
815 endif |
|
816 |
|
817 xdat = obj.xdata; |
|
818 ydat = obj.ydata; |
|
819 zdat = obj.zdata; |
|
820 cdat = obj.cdata; |
7110
|
821 |
7109
|
822 if (xautoscale) |
|
823 tx = xdat(:); |
|
824 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, tx); |
|
825 endif |
|
826 if (yautoscale) |
|
827 ty = ydat(:); |
|
828 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ty); |
|
829 endif |
|
830 if (zautoscale) |
|
831 tz = zdat(:); |
|
832 [zmin, zmax, zminp] = get_data_limits (zmin, zmax, zminp, tz); |
6405
|
833 endif |
7109
|
834 |
|
835 err = false; |
|
836 if (! size_equal(zdat, cdat)) |
6405
|
837 err = true; |
7109
|
838 endif |
|
839 if (isvector (xdat) && isvector (ydat) && ismatrix (zdat)) |
7110
|
840 if (rows (zdat) == length (ydat) |
|
841 && columns (zdat) == length (xdat)) |
7109
|
842 [xdat, ydat] = meshgrid (xdat, ydat); |
|
843 else |
|
844 err = true; |
|
845 endif |
|
846 elseif (ismatrix (xdat) && ismatrix (ydat) && ismatrix (zdat)) |
|
847 if (! (size_equal (xdat, ydat) && size_equal (xdat, zdat))) |
|
848 err = true; |
|
849 endif |
|
850 else |
|
851 err = true; |
|
852 endif |
|
853 if (err) |
|
854 error ("__go_draw_axes__: invalid grid data"); |
6405
|
855 endif |
7109
|
856 xlen = columns (zdat); |
|
857 ylen = rows (zdat); |
|
858 if (xlen == columns (xdat) && xlen == columns (ydat) |
|
859 && ylen == rows (xdat) && ylen == rows (ydat)) |
|
860 len = 4 * xlen; |
|
861 zz = zeros (ylen, len); |
|
862 k = 1; |
|
863 for kk = 1:4:len |
|
864 zz(:,kk) = xdat(:,k); |
|
865 zz(:,kk+1) = ydat(:,k); |
|
866 zz(:,kk+2) = zdat(:,k); |
|
867 zz(:,kk+3) = cdat(:,k); |
|
868 k++; |
|
869 endfor |
7170
|
870 data{data_idx} = zz.'; |
7109
|
871 endif |
|
872 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
|
873 |
|
874 fputs (plot_stream, "unset parametric;\n"); |
|
875 fputs (plot_stream, "set style data lines;\n"); |
|
876 fputs (plot_stream, "set surface;\n"); |
|
877 fputs (plot_stream, "unset contour;\n"); |
|
878 |
7119
|
879 ## Interpolation does not work for flat surfaces (e.g. pcolor) |
|
880 ## and color mapping --> currently set empty. |
|
881 interp_str = ""; |
|
882 flat_interp_face = (strncmp (obj.facecolor, "flat", 4) |
|
883 || strncmp (obj.facecolor, "interp", 6)); |
|
884 flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4) |
|
885 || strncmp (obj.edgecolor, "interp", 6)); |
7154
|
886 |
|
887 facecolor_none_or_white = (strncmp (obj.facecolor, "none", 4) |
|
888 || (isnumeric (obj.facecolor) |
|
889 && all (obj.facecolor == 1))); |
7149
|
890 if (strncmp (obj.facecolor, "none", 4)) |
7175
|
891 if (isnan (hidden_removal)) |
|
892 hidden_removal = false; |
|
893 endif |
|
894 else |
|
895 hidden_removal = true; |
7149
|
896 endif |
|
897 |
7119
|
898 if (flat_interp_face |
7154
|
899 || (flat_interp_edge && facecolor_none_or_white)) |
7189
|
900 withclause{data_idx} = "with line palette"; |
7119
|
901 endif |
7109
|
902 |
7189
|
903 if (have_newer_gnuplot) |
|
904 dord = "depthorder"; |
|
905 else |
|
906 dord = ""; |
|
907 endif |
7109
|
908 |
7154
|
909 if (facecolor_none_or_white) |
7189
|
910 ## Ensure faces aren't drawn |
|
911 fprintf (plot_stream, "unset pm3d;\n"); |
7119
|
912 elseif (flat_interp_face && strncmp (obj.edgecolor, "flat", 4)) |
7189
|
913 fprintf (plot_stream, "set pm3d at s %s %s;\n", |
|
914 interp_str, dord); |
7119
|
915 else |
|
916 if (strncmp (obj.edgecolor, "none", 4)) |
7189
|
917 fprintf (plot_stream, "set pm3d at s %s ;\n", |
|
918 interp_str, dord); |
7109
|
919 else |
7119
|
920 edgecol = obj.edgecolor; |
|
921 if (ischar (obj.edgecolor)) |
|
922 edgecol = [0,0,0]; |
|
923 endif |
7189
|
924 fprintf (plot_stream, "set pm3d at s hidden3d %d %s %s;\n", |
|
925 data_idx, interp_str, dord); |
7119
|
926 |
|
927 if (have_newer_gnuplot) |
7110
|
928 fprintf (plot_stream, |
|
929 "set style line %d linecolor rgb \"#%02x%02x%02x\" lw %f;\n", |
7109
|
930 data_idx, round (255*edgecol), obj.linewidth); |
7119
|
931 else |
|
932 if (isequal (edgecol, [0,0,0])) |
|
933 typ = -1; |
|
934 elseif (isequal (edgecol, [1,0,0])) |
|
935 typ = 1; |
|
936 elseif (isequal (edgecol, [0,1,0])) |
|
937 typ = 2; |
|
938 elseif (isequal (edgecol, [0,0,1])) |
|
939 typ = 3; |
|
940 elseif (isequal (edgecol, [1,0,1])) |
|
941 typ = 4; |
|
942 elseif (isequal (edgecol, [0,1,1])) |
|
943 typ = 5; |
|
944 elseif (isequal (edgecol, [1,1,1])) |
|
945 typ = -1; |
|
946 elseif (isequal (edgecol, [1,1,0])) |
|
947 typ = 7; |
|
948 else |
|
949 typ = -1; |
|
950 endif |
|
951 fprintf (plot_stream, |
|
952 "set style line %d lt %d lw %f;\n", |
|
953 data_idx, typ, obj.linewidth); |
|
954 endif |
7109
|
955 endif |
7119
|
956 endif |
6405
|
957 endif |
|
958 |
|
959 case "text" |
7189
|
960 [label, f, s] = __maybe_munge_text__ (enhanced, obj, "string", |
|
961 have_newer_gnuplot); |
6405
|
962 lpos = obj.position; |
|
963 halign = obj.horizontalalignment; |
6724
|
964 angle = obj.rotation; |
6752
|
965 units = obj.units; |
6829
|
966 color = obj.color; |
6758
|
967 if (strcmpi (units, "normalized")) |
6752
|
968 units = "graph"; |
|
969 else |
|
970 units = ""; |
|
971 endif |
|
972 |
6829
|
973 if (isnumeric (color)) |
|
974 if (have_newer_gnuplot) |
|
975 colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"", |
|
976 round (255*color)); |
|
977 else |
|
978 if (isequal (color, [0,0,0])) |
|
979 typ = -1; |
|
980 elseif (isequal (color, [1,0,0])) |
|
981 typ = 1; |
|
982 elseif (isequal (color, [0,1,0])) |
|
983 typ = 2; |
|
984 elseif (isequal (color, [0,0,1])) |
|
985 typ = 3; |
|
986 elseif (isequal (color, [1,0,1])) |
|
987 typ = 4; |
|
988 elseif (isequal (color, [0,1,1])) |
|
989 typ = 5; |
|
990 elseif (isequal (color, [1,1,1])) |
|
991 typ = -1; |
|
992 elseif (isequal (color, [1,1,0])) |
|
993 typ = 7; |
|
994 else |
|
995 typ = -1; |
|
996 endif |
|
997 colorspec = sprintf ("textcolor lt %d", typ); |
|
998 endif |
|
999 endif |
|
1000 |
6405
|
1001 if (nd == 3) |
6724
|
1002 fprintf (plot_stream, |
7162
|
1003 "set label \"%s\" at %s %.15g,%.15g,%.15g font \"%s,%d\" %s rotate by %f %s;\n", |
|
1004 undo_string_escapes (label), units, lpos(1), |
|
1005 lpos(2), lpos(3), f, s, halign, angle, colorspec); |
6405
|
1006 else |
7162
|
1007 fprintf (plot_stream, |
|
1008 "set label \"%s\" at %s %.15g,%.15g font \"%s,%d\" %s rotate by %f %s;\n", |
|
1009 undo_string_escapes (label), units, |
|
1010 lpos(1), lpos(2), f, s, halign, angle, colorspec); |
6405
|
1011 endif |
|
1012 |
|
1013 otherwise |
|
1014 error ("__go_draw_axes__: unknown object class, %s", |
|
1015 obj.type); |
|
1016 endswitch |
|
1017 |
|
1018 endfor |
|
1019 |
7175
|
1020 if (isnan(hidden_removal) || hidden_removal) |
7149
|
1021 fputs (plot_stream, "set hidden3d;\n"); |
|
1022 else |
|
1023 fputs (plot_stream, "unset hidden3d;\n"); |
|
1024 endif |
|
1025 |
7152
|
1026 have_data = (! (isempty (data) || any (cellfun (@isempty, data)))); |
6405
|
1027 |
|
1028 if (xautoscale && have_data) |
|
1029 xlim = get_axis_limits (xmin, xmax, xminp, xlogscale); |
7008
|
1030 if (isempty (xlim)) |
|
1031 return; |
|
1032 endif |
6405
|
1033 set (h, "xlim", xlim, "xlimmode", "auto"); |
|
1034 else |
|
1035 xlim = axis_obj.xlim; |
|
1036 endif |
6758
|
1037 if (strcmpi (axis_obj.xdir, "reverse")) |
6405
|
1038 xdir = "reverse"; |
|
1039 else |
|
1040 xdir = "noreverse"; |
|
1041 endif |
7115
|
1042 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", |
|
1043 xaxisloc, xlim, xdir); |
6405
|
1044 |
|
1045 if (yautoscale && have_data) |
|
1046 ylim = get_axis_limits (ymin, ymax, yminp, ylogscale); |
7008
|
1047 if (isempty (ylim)) |
|
1048 return; |
|
1049 endif |
6405
|
1050 set (h, "ylim", ylim, "ylimmode", "auto"); |
|
1051 else |
|
1052 ylim = axis_obj.ylim; |
|
1053 endif |
6758
|
1054 if (strcmpi (axis_obj.ydir, "reverse")) |
6405
|
1055 ydir = "reverse"; |
|
1056 else |
|
1057 ydir = "noreverse"; |
|
1058 endif |
7110
|
1059 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", |
|
1060 yaxisloc, ylim, ydir); |
6405
|
1061 |
7119
|
1062 if (nd == 3) |
6405
|
1063 if (zautoscale && have_data) |
|
1064 zlim = get_axis_limits (zmin, zmax, zminp, zlogscale); |
7008
|
1065 if (isempty (zlim)) |
|
1066 return; |
|
1067 endif |
6405
|
1068 set (h, "zlim", zlim, "zlimmode", "auto"); |
|
1069 else |
|
1070 zlim = axis_obj.zlim; |
|
1071 endif |
6758
|
1072 if (strcmpi (axis_obj.zdir, "reverse")) |
6405
|
1073 zdir = "reverse"; |
|
1074 else |
|
1075 zdir = "noreverse"; |
|
1076 endif |
6942
|
1077 fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir); |
6405
|
1078 endif |
7110
|
1079 |
7189
|
1080 if (cautoscale && have_data) |
|
1081 set (h, "clim", clim, "climmode", "auto"); |
|
1082 endif |
|
1083 if (! any (isinf (clim))) |
|
1084 fprintf (plot_stream, "set cbrange [%g:%g];\n", clim); |
|
1085 endif |
|
1086 |
6758
|
1087 if (strcmpi (axis_obj.box, "on")) |
7119
|
1088 if (nd == 3) |
6405
|
1089 fputs (plot_stream, "set border 4095;\n"); |
|
1090 else |
|
1091 fputs (plot_stream, "set border 431;\n"); |
|
1092 endif |
|
1093 else |
7119
|
1094 if (nd == 3) |
6405
|
1095 fputs (plot_stream, "set border 895;\n"); |
|
1096 else |
|
1097 fputs (plot_stream, "set border 3;\n"); |
|
1098 fputs (plot_stream, "set xtics nomirror; set ytics nomirror;\n"); |
|
1099 endif |
|
1100 endif |
|
1101 |
7060
|
1102 if (strcmpi (axis_obj.visible, "off")) |
|
1103 fputs (plot_stream, "unset border; unset tics\n"); |
|
1104 endif |
|
1105 |
6758
|
1106 if (strcmpi (axis_obj.key, "on")) |
|
1107 if (strcmpi (axis_obj.keybox, "on")) |
6405
|
1108 box = "box"; |
|
1109 else |
|
1110 box = "nobox"; |
|
1111 endif |
|
1112 inout = "inside"; |
6977
|
1113 keypos = axis_obj.keypos; |
|
1114 if (ischar (keypos)) |
|
1115 keypos = lower (keypos); |
|
1116 keyout = findstr (keypos, "outside"); |
|
1117 if (! isempty (keyout)) |
|
1118 inout = "outside"; |
7119
|
1119 keypos = keypos(1:keyout-1); |
6977
|
1120 endif |
|
1121 endif |
|
1122 switch (keypos) |
6405
|
1123 case -1 |
6977
|
1124 pos = "right top"; |
6405
|
1125 inout = "outside"; |
|
1126 case 1 |
|
1127 pos = "right top"; |
|
1128 case 2 |
|
1129 pos = "left top"; |
|
1130 case 3 |
|
1131 pos = "left bottom"; |
6977
|
1132 case {4, 0} |
6405
|
1133 pos = "right bottom"; |
6977
|
1134 case "north" |
|
1135 pos = "center top"; |
|
1136 case "south" |
|
1137 pos = "center bottom"; |
|
1138 case "east" |
|
1139 pos = "right center"; |
|
1140 case "west" |
|
1141 pos = "left center"; |
|
1142 case "northeast" |
|
1143 pos = "right top"; |
|
1144 case "northwest" |
|
1145 pos = "left top"; |
|
1146 case "southeast" |
|
1147 pos = "right bottom"; |
|
1148 case "southwest" |
|
1149 pos = "left bottom"; |
|
1150 case "best" |
|
1151 pos = ""; |
|
1152 warning ("legend: 'Best' not yet implemented for location specifier.\n"); |
|
1153 ## least conflict with data in plot |
|
1154 ## least unused space outside plot |
6405
|
1155 otherwise |
|
1156 pos = ""; |
|
1157 endswitch |
|
1158 if (! have_newer_gnuplot) |
|
1159 inout = ""; |
|
1160 endif |
|
1161 fprintf (plot_stream, "set key %s %s %s;\n", inout, pos, box); |
|
1162 else |
|
1163 fputs (plot_stream, "unset key;\n"); |
|
1164 endif |
|
1165 |
|
1166 fputs (plot_stream, "set style data lines;\n"); |
|
1167 |
|
1168 if (! use_gnuplot_for_images) |
|
1169 for i = 1:ximg_data_idx |
|
1170 view_fcn (xlim, ylim, ximg_data{i}, view_zoom, view_cmd); |
|
1171 endfor |
|
1172 endif |
|
1173 |
7189
|
1174 cmap = parent_figure_obj.colormap; |
|
1175 cmap_sz = rows(cmap); |
|
1176 if (length(cmap) > 0) |
|
1177 if (have_newer_gnuplot) |
|
1178 fprintf (plot_stream, |
|
1179 "set palette positive color model RGB maxcolors %i;\n", |
|
1180 cmap_sz); |
|
1181 fprintf (plot_stream, |
|
1182 "set palette file \"-\" binary record=%d using 1:2:3:4;\n", |
|
1183 cmap_sz); |
|
1184 fwrite (plot_stream, [1:cmap_sz; cmap.'], "float32"); |
|
1185 else |
|
1186 fputs (plot_stream, "set palette defined ("); |
|
1187 for i = 1: cmap_sz |
|
1188 col = floor(cmap(i, :) * 255); |
|
1189 if (i == 1) |
|
1190 fputs (plot_stream, sprintf("%d \"#%02X%02X%02X\"", i - 1, |
|
1191 col(1), col(2), col(3))); |
|
1192 else |
|
1193 fputs (plot_stream, sprintf(", %d \"#%02X%02X%02X\"", i - 1, |
|
1194 col(1), col(2), col(3))); |
|
1195 endif |
|
1196 endfor |
|
1197 fputs (plot_stream, ");\n"); |
|
1198 endif |
|
1199 endif |
|
1200 |
|
1201 if (strcmp (axis_obj.__colorbar__, "none")) |
|
1202 fputs (plot_stream, "unset colorbox;\n"); |
|
1203 else |
|
1204 ## FIXME If cbox_mirror is true we want to invert the tic labels |
|
1205 ## but gnuplot doesn't allow that |
|
1206 fputs (plot_stream, |
|
1207 sprintf ("set colorbox %s user origin %f,%f size %f,%f;\n", |
|
1208 cbox_orient, cbox_origin, cbox_size)); |
|
1209 endif |
|
1210 |
6405
|
1211 if (have_data) |
|
1212 if (nd == 2) |
|
1213 plot_cmd = "plot"; |
|
1214 else |
|
1215 plot_cmd = "splot"; |
|
1216 rot_x = 90 - axis_obj.view(2); |
|
1217 rot_z = axis_obj.view(1); |
|
1218 while (rot_z < 0) |
|
1219 rot_z += 360; |
|
1220 endwhile |
6461
|
1221 fputs (plot_stream, "set ticslevel 0;\n"); |
6914
|
1222 fprintf (plot_stream, "set view %.15g, %.15g;\n", rot_x, rot_z); |
6405
|
1223 endif |
6611
|
1224 fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd, |
6464
|
1225 usingclause{1}, titlespec{1}, withclause{1}); |
6405
|
1226 for i = 2:data_idx |
6611
|
1227 fprintf (plot_stream, ", \"-\" %s %s %s \\\n", |
6464
|
1228 usingclause{i}, titlespec{i}, withclause{i}); |
6405
|
1229 endfor |
|
1230 fputs (plot_stream, ";\n"); |
|
1231 for i = 1:data_idx |
6464
|
1232 if (is_image_data(i)) |
|
1233 fwrite (plot_stream, data{i}, "float32"); |
|
1234 else |
7119
|
1235 __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i), |
|
1236 have_cdata(i)); |
6405
|
1237 endif |
|
1238 endfor |
6431
|
1239 else |
|
1240 fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n"); |
6405
|
1241 endif |
|
1242 |
|
1243 fflush (plot_stream); |
|
1244 |
|
1245 else |
|
1246 print_usage (); |
7109
|
1247 endif |
6405
|
1248 |
|
1249 endfunction |
|
1250 |
6453
|
1251 function [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat, tx) |
7119
|
1252 if (! (isempty (xdat) || (nargin > 4 && isempty (tx)))) |
7115
|
1253 xdat = xdat(! isinf (xdat)); |
|
1254 xmin = min (xmin, min (xdat)); |
|
1255 xmax = max (xmax, max (xdat)); |
|
1256 if (nargin == 5) |
|
1257 tx = tx(! isinf (xdat) & tx > 0); |
|
1258 if (! isempty (tx)) |
|
1259 xminp = min (xminp, min (tx)); |
|
1260 endif |
|
1261 else |
|
1262 tmp = min (xdat(xdat > 0)); |
|
1263 if (! isempty (tmp)) |
|
1264 xminp = min (xminp, tmp); |
|
1265 endif |
7012
|
1266 endif |
6453
|
1267 endif |
|
1268 endfunction |
|
1269 |
6405
|
1270 ## Attempt to make "nice" limits from the actual max and min of the |
|
1271 ## data. For log plots, we will also use the smallest strictly positive |
|
1272 ## value. |
|
1273 |
|
1274 function lim = get_axis_limits (min_val, max_val, min_pos, logscale) |
|
1275 |
7115
|
1276 if (! (isinf (min_val) || isinf (max_val))) |
|
1277 if (logscale) |
|
1278 if (isinf (min_pos)) |
|
1279 lim = []; |
|
1280 warning ("axis: logscale with no positive values to plot"); |
|
1281 return; |
|
1282 endif |
|
1283 if (min_val <= 0) |
|
1284 warning ("axis: omitting nonpositive data in log plot"); |
|
1285 min_val = min_pos; |
|
1286 endif |
|
1287 ## FIXME -- maybe this test should also be relative? |
|
1288 if (abs (min_val - max_val) < sqrt (eps)) |
|
1289 min_val *= 0.9; |
|
1290 max_val *= 1.1; |
|
1291 endif |
|
1292 min_val = 10 ^ floor (log10 (min_val)); |
|
1293 max_val = 10 ^ ceil (log10 (max_val)); |
|
1294 else |
|
1295 if (min_val == 0 && max_val == 0) |
|
1296 min_val = -1; |
|
1297 max_val = 1; |
|
1298 ## FIXME -- maybe this test should also be relative? |
|
1299 elseif (abs (min_val - max_val) < sqrt (eps)) |
|
1300 min_val -= 0.1 * abs (min_val); |
|
1301 max_val += 0.1 * abs (max_val); |
|
1302 endif |
|
1303 ## FIXME -- to do a better job, we should consider the tic spacing. |
|
1304 scale = 10 ^ floor (log10 (max_val - min_val) - 1); |
|
1305 min_val = scale * floor (min_val / scale); |
|
1306 max_val = scale * ceil (max_val / scale); |
6405
|
1307 endif |
|
1308 endif |
|
1309 |
|
1310 lim = [min_val, max_val]; |
|
1311 |
|
1312 endfunction |
|
1313 |
6465
|
1314 function [style, typ, with] = do_linestyle_command (obj, idx, plot_stream) |
6405
|
1315 |
6413
|
1316 persistent have_newer_gnuplot ... |
|
1317 = compare_versions (__gnuplot_version__ (), "4.0", ">"); |
6405
|
1318 |
|
1319 if (have_newer_gnuplot) |
|
1320 fprintf (plot_stream, "set style line %d default;\n", idx); |
|
1321 endif |
|
1322 fprintf (plot_stream, "set style line %d", idx); |
|
1323 |
|
1324 found_style = false; |
6425
|
1325 typ = NaN; |
6465
|
1326 with = ""; |
6405
|
1327 |
6425
|
1328 if (isfield (obj, "color")) |
6405
|
1329 color = obj.color; |
|
1330 if (isnumeric (color)) |
6425
|
1331 if (have_newer_gnuplot) |
|
1332 fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", |
|
1333 round (255*color)); |
|
1334 else |
|
1335 if (isequal (color, [0,0,0])) |
|
1336 typ = -1; |
|
1337 elseif (isequal (color, [1,0,0])) |
|
1338 typ = 1; |
|
1339 elseif (isequal (color, [0,1,0])) |
|
1340 typ = 2; |
|
1341 elseif (isequal (color, [0,0,1])) |
|
1342 typ = 3; |
|
1343 elseif (isequal (color, [1,0,1])) |
|
1344 typ = 4; |
|
1345 elseif (isequal (color, [0,1,1])) |
|
1346 typ = 5; |
|
1347 elseif (isequal (color, [1,1,1])) |
|
1348 typ = 6; |
|
1349 elseif (isequal (color, [1,1,0])) |
|
1350 typ = 7; |
|
1351 else |
|
1352 typ = 2; |
|
1353 endif |
|
1354 endif |
6405
|
1355 endif |
|
1356 found_style = true; |
|
1357 endif |
|
1358 |
|
1359 if (isfield (obj, "linestyle")) |
|
1360 switch (obj.linestyle) |
|
1361 case "-" |
6415
|
1362 lt = "1"; |
6405
|
1363 case "--" |
6415
|
1364 lt = "2"; |
6405
|
1365 case ":" |
6415
|
1366 lt = "3"; |
6405
|
1367 case "-." |
6415
|
1368 lt = "6"; |
6405
|
1369 case "none" |
|
1370 lt = ""; |
|
1371 otherwise |
|
1372 lt = ""; |
|
1373 endswitch |
6843
|
1374 |
|
1375 ## FIXME -- linetype is currently broken, since it disables the |
|
1376 ## gnuplot default dashed and solid linestyles with the only |
|
1377 ## benefit of being able to specify '--' and get a single sized |
|
1378 ## dashed line of identical dash pattern for all called this way. |
|
1379 ## All dash patterns are a subset of "with lines" and none of the |
|
1380 ## lt specifications will correctly propagate into the x11 terminal |
|
1381 ## or the print command. Therefore, it is currently disabled in |
|
1382 ## order to allow print (..., "-dashed") etc. to work correctly. |
|
1383 |
|
1384 ## if (! isempty (lt)) |
|
1385 ## fprintf (plot_stream, " linetype %s", lt); |
|
1386 ## found_style = true; |
|
1387 ## endif |
|
1388 |
6405
|
1389 else |
|
1390 lt = ""; |
|
1391 endif |
|
1392 |
|
1393 if (isfield (obj, "linewidth")) |
6465
|
1394 if (have_newer_gnuplot) |
|
1395 fprintf (plot_stream, " linewidth %f", obj.linewidth); |
|
1396 else |
|
1397 with = sprintf ("%s lw %f", with, obj.linewidth); |
|
1398 endif |
6405
|
1399 found_style = true; |
|
1400 endif |
|
1401 |
|
1402 if (isfield (obj, "marker")) |
|
1403 switch (obj.marker) |
|
1404 case "+" |
|
1405 pt = "1"; |
|
1406 case "o" |
6413
|
1407 pt = "6"; |
6405
|
1408 case "*" |
|
1409 pt = "3"; |
|
1410 case "." |
7078
|
1411 pt = "0"; |
6405
|
1412 case "x" |
|
1413 pt = "2"; |
|
1414 case {"square", "s"} |
|
1415 pt = "5"; |
|
1416 case {"diamond", "d"} |
|
1417 pt = "13"; |
|
1418 case "^" |
|
1419 pt = "9"; |
|
1420 case "v" |
|
1421 pt = "11"; |
|
1422 case ">" |
|
1423 pt = "8"; |
|
1424 case "<" |
|
1425 pt = "10"; |
|
1426 case {"pentagram", "p"} |
|
1427 pt = "4"; |
|
1428 case {"hexagram", "h"} |
6413
|
1429 pt = "12"; |
6405
|
1430 case "none" |
|
1431 pt = ""; |
|
1432 otherwise |
|
1433 pt = ""; |
|
1434 endswitch |
|
1435 if (! isempty (pt)) |
6465
|
1436 if (have_newer_gnuplot) |
|
1437 fprintf (plot_stream, " pointtype %s", pt); |
|
1438 else |
|
1439 with = sprintf ("%s pt %s", with, pt); |
|
1440 endif |
6405
|
1441 found_style = true; |
|
1442 endif |
|
1443 else |
|
1444 pt = ""; |
|
1445 endif |
|
1446 |
|
1447 style = "lines"; |
|
1448 if (isempty (lt)) |
|
1449 if (! isempty (pt)) |
|
1450 style = "points"; |
|
1451 endif |
|
1452 elseif (! isempty (pt)) |
|
1453 style = "linespoints"; |
|
1454 endif |
|
1455 |
6465
|
1456 if (isfield (obj, "markersize")) |
|
1457 if (have_newer_gnuplot) |
|
1458 fprintf (plot_stream, " pointsize %f", obj.markersize); |
|
1459 else |
6758
|
1460 if (! strcmpi (style, "lines")) |
6465
|
1461 with = sprintf ("%s ps %f", with, obj.markersize); |
|
1462 endif |
|
1463 endif |
|
1464 found_style = true; |
|
1465 endif |
|
1466 |
6405
|
1467 if (have_newer_gnuplot && ! found_style) |
|
1468 fputs (plot_stream, " default"); |
|
1469 endif |
|
1470 |
|
1471 fputs (plot_stream, ";\n"); |
|
1472 |
|
1473 endfunction |
6510
|
1474 |
7119
|
1475 function __gnuplot_write_data__ (plot_stream, data, nd, parametric, cdata) |
6510
|
1476 |
|
1477 ## DATA is already transposed. |
|
1478 |
|
1479 ## FIXME -- this may need to be converted to C++ for speed. |
|
1480 |
6605
|
1481 ## Convert NA elements to normal NaN values because fprintf writes |
|
1482 ## "NA" and that confuses gnuplot. |
|
1483 idx = find (isna (data)); |
|
1484 if (any (idx)) |
|
1485 data(idx) = NaN; |
|
1486 endif |
|
1487 |
6510
|
1488 if (nd == 2) |
|
1489 nan_elts = find (sum (isnan (data))); |
6914
|
1490 fmt = strcat (repmat ("%.15g ", 1, rows (data)), "\n"); |
6510
|
1491 if (isempty (nan_elts)) |
|
1492 fprintf (plot_stream, fmt, data); |
|
1493 else |
|
1494 n = columns (data); |
|
1495 have_nans = true; |
|
1496 num_nan_elts = numel (nan_elts); |
|
1497 k = 1; |
|
1498 for i = 1:n |
|
1499 if (have_nans && i == nan_elts(k)) |
|
1500 fputs (plot_stream, "\n"); |
|
1501 have_nans = ++k <= num_nan_elts; |
|
1502 else |
|
1503 fprintf (plot_stream, fmt, data(:,i)); |
|
1504 endif |
|
1505 endfor |
|
1506 endif |
7109
|
1507 elseif (nd == 3) |
6510
|
1508 ## FIXME -- handle NaNs here too? |
|
1509 if (parametric) |
6914
|
1510 fprintf (plot_stream, "%.15g %.15g %.15g\n", data); |
6510
|
1511 else |
7170
|
1512 nr = rows (data); |
7119
|
1513 if (cdata) |
7170
|
1514 for j = 1:4:nr |
|
1515 fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data(j:j+3,:)); |
7119
|
1516 fputs (plot_stream, "\n"); |
|
1517 endfor |
|
1518 else |
7170
|
1519 for j = 1:3:nr |
|
1520 fprintf (plot_stream, "%.15g %.15g %.15g\n", data(j:j+2,:)); |
7119
|
1521 fputs (plot_stream, "\n"); |
|
1522 endfor |
|
1523 endif |
7109
|
1524 endif |
6510
|
1525 endif |
|
1526 fputs (plot_stream, "e\n"); |
|
1527 |
|
1528 endfunction |
6745
|
1529 |
|
1530 function do_tics (obj, plot_stream) |
6809
|
1531 if (strcmpi (obj.xaxislocation, "top")) |
|
1532 do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, |
|
1533 "x2", plot_stream); |
|
1534 do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, |
|
1535 "x", plot_stream); |
|
1536 else |
|
1537 do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, |
|
1538 "x", plot_stream); |
|
1539 do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, |
|
1540 "x2", plot_stream); |
|
1541 endif |
|
1542 if (strcmpi (obj.yaxislocation, "right")) |
|
1543 do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, |
|
1544 "y2", plot_stream); |
|
1545 do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, |
|
1546 "y", plot_stream); |
|
1547 else |
|
1548 do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, |
|
1549 "y", plot_stream); |
|
1550 do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, |
|
1551 "y2", plot_stream); |
|
1552 endif |
6745
|
1553 do_tics_1 (obj.ztickmode, obj.ztick, obj.zticklabelmode, obj.zticklabel, |
|
1554 "z", plot_stream); |
|
1555 endfunction |
|
1556 |
|
1557 function do_tics_1 (ticmode, tics, labelmode, labels, ax, plot_stream) |
6758
|
1558 if (strcmpi (ticmode, "manual")) |
6745
|
1559 if (isempty (tics)) |
|
1560 fprintf (plot_stream, "unset %stics;\n", ax); |
6758
|
1561 elseif (strcmpi (labelmode, "manual") && ! isempty (labels)) |
6751
|
1562 if (ischar (labels)) |
|
1563 labels = cellstr (labels); |
|
1564 endif |
6745
|
1565 if (iscellstr (labels)) |
6751
|
1566 k = 1; |
|
1567 ntics = numel (tics); |
|
1568 nlabels = numel (labels); |
6745
|
1569 fprintf (plot_stream, "set format %s \"%%s\";\n", ax); |
|
1570 fprintf (plot_stream, "set %stics (", ax); |
|
1571 for i = 1:ntics |
6920
|
1572 fprintf (plot_stream, " \"%s\" %g", labels(k++), tics(i)) |
6745
|
1573 if (i < ntics) |
|
1574 fputs (plot_stream, ", "); |
|
1575 endif |
|
1576 if (k > nlabels) |
|
1577 k = 1; |
|
1578 endif |
|
1579 endfor |
|
1580 fputs (plot_stream, ");\n"); |
|
1581 else |
|
1582 error ("unsupported type of ticklabel"); |
|
1583 endif |
|
1584 else |
6920
|
1585 fprintf (plot_stream, "set format %s \"%%g\";\n", ax); |
6745
|
1586 fprintf (plot_stream, "set %stics (", ax); |
6920
|
1587 fprintf (plot_stream, " %g,", tics(1:end-1)); |
|
1588 fprintf (plot_stream, " %g);\n", tics(end)); |
6745
|
1589 endif |
|
1590 else |
6920
|
1591 fprintf (plot_stream, "set format %s \"%%g\";\n", ax); |
6745
|
1592 fprintf (plot_stream, "set %stics;\n", ax); |
|
1593 endif |
|
1594 endfunction |
7163
|
1595 |
7189
|
1596 function [f, s, fnt, it, bld] = get_fontname_and_size (t) |
7163
|
1597 if (isempty (t.fontname)) |
7189
|
1598 fnt = "helvetica"; |
7163
|
1599 else |
7189
|
1600 fnt = tolower (t.fontname); |
7168
|
1601 endif |
7189
|
1602 f = fnt; |
|
1603 it = false; |
|
1604 bld = false; |
7168
|
1605 if (! isempty (t.fontweight) && strcmp (tolower (t.fontweight), "bold")) |
|
1606 if (! isempty(t.fontangle) |
|
1607 && (strcmp (tolower (t.fontangle), "italic") |
|
1608 || strcmp (tolower (t.fontangle), "oblique"))) |
|
1609 f = strcat (f, "-bolditalic"); |
7189
|
1610 it = true; |
|
1611 bld = true; |
7168
|
1612 else |
|
1613 f = strcat (f, "-bold"); |
7189
|
1614 bld = true; |
7168
|
1615 endif |
|
1616 elseif (! isempty(t.fontangle) |
|
1617 && (strcmp (tolower (t.fontangle), "italic") |
|
1618 || strcmp (tolower (t.fontangle), "oblique"))) |
|
1619 f = strcat (f, "-italic"); |
7189
|
1620 it = true; |
7163
|
1621 endif |
|
1622 if (isempty (t.fontsize)) |
|
1623 s = 10; |
|
1624 else |
|
1625 s = t.fontsize; |
|
1626 endif |
|
1627 endfunction |
7189
|
1628 |
|
1629 function [str, f, s] = __maybe_munge_text__ (enhanced, obj, fld, |
|
1630 have_newer_gnuplot) |
|
1631 persistent warned_latex = false; |
|
1632 |
|
1633 if (strcmp (fld, "string")) |
|
1634 [f, s, fnt, it, bld] = get_fontname_and_size (obj); |
|
1635 else |
|
1636 f = "Helvectica"; |
|
1637 s = 10; |
|
1638 fnt = f; |
|
1639 it = false; |
|
1640 bld = false; |
|
1641 endif |
|
1642 |
|
1643 str = getfield (obj, fld); |
|
1644 if (enhanced) |
|
1645 if (strcmp (obj.interpreter, "tex")) |
|
1646 str = __tex2enhanced__ (str, fnt, it, bld); |
|
1647 if (! have_newer_gnuplot) |
|
1648 ## Set the font to work around gnuplot 4.0 X11 enhanced terminal bug |
|
1649 str = strcat ('{/', f, ' ', str, ' }'); |
|
1650 endif |
|
1651 elseif (strcmp (obj.interpreter, "latex")) |
|
1652 if (! warned_latex) |
|
1653 warning ("latex text objects not supported"); |
|
1654 warned_latex = true; |
|
1655 endif |
|
1656 endif |
|
1657 endif |
|
1658 endfunction |
|
1659 |
|
1660 function str = __tex2enhanced__ (str, fnt, it, bld) |
|
1661 persistent sym = __setup_sym_table__ (); |
|
1662 persistent flds = fieldnames (sym); |
|
1663 |
|
1664 [s, e, m] = regexp(str,'\\([a-zA-Z]+|0)','start','end','matches'); |
|
1665 |
|
1666 for i = length (s) : -1 : 1 |
|
1667 ## special case for "\0" and replace with "{/Symbol \306}' |
|
1668 if (strncmp (m{i}, '\0', 2)) |
7190
|
1669 str = strcat (str(1:s(i) - 1), '{/Symbol \306}', str(s(i) + 2:end)); |
7189
|
1670 else |
|
1671 f = m{i}(2:end); |
|
1672 if (isfield (sym, f)) |
|
1673 g = getfield(sym, f); |
|
1674 ## FIXME The symbol font doesn't seem to support bold or italic |
|
1675 ##if (bld) |
|
1676 ## if (it) |
|
1677 ## g = regexprep (g, '/Symbol', '/Symbol-bolditalic'); |
|
1678 ## else |
|
1679 ## g = regexprep (g, '/Symbol', '/Symbol-bold'); |
|
1680 ## endif |
|
1681 ##elseif (it) |
|
1682 ## g = regexprep (g, '/Symbol', '/Symbol-italic'); |
|
1683 ##endif |
|
1684 str = strcat (str(1:s(i) - 1), g, str(e(i) + 1:end)); |
|
1685 elseif (strncmp (f, "rm", 2)) |
|
1686 bld = false; |
|
1687 it = false; |
|
1688 str = strcat (str(1:s(i) - 1), '/', fnt, ' ', str(s(i) + 3:end)); |
|
1689 elseif (strncmp (f, "it", 2) || strncmp (f, "sl", 2)) |
|
1690 it = true; |
|
1691 if (bld) |
|
1692 str = strcat (str(1:s(i) - 1), '/', fnt, '-bolditalic ', |
|
1693 str(s(i) + 3:end)); |
|
1694 else |
|
1695 str = strcat (str(1:s(i) - 1), '/', fnt, '-italic ', |
|
1696 str(s(i) + 3:end)); |
|
1697 endif |
|
1698 elseif (strncmp (f, "bf", 2)) |
|
1699 bld = true; |
|
1700 if (it) |
|
1701 str = strcat (str(1:s(i) - 1), '/', fnt, '-bolditalic ', |
|
1702 str(2(i) + 3:end)); |
|
1703 else |
|
1704 str = strcat (str(1:s(i) - 1), '/', fnt, '-bold ', |
|
1705 str(s(i) + 3:end)); |
|
1706 endif |
|
1707 elseif (strcmp (f, "color")) |
|
1708 ## FIXME Ignore \color but remove trailing {} block as well |
|
1709 d = strfind(str(e(i) + 1:end),'}'); |
|
1710 if (isempty (d)) |
|
1711 warning ('syntax error in \color argument'); |
|
1712 else |
|
1713 str = strcat (str(1:s(i) - 1), str(e(i) + d + 1:end)); |
|
1714 endif |
|
1715 elseif(strcmp (f, "fontname")) |
|
1716 b1 = strfind(str(e(i) + 1:end),'{'); |
|
1717 b2 = strfind(str(e(i) + 1:end),'}'); |
|
1718 if (isempty(b1) || isempty(b2)) |
|
1719 warning ('syntax error in \fontname argument'); |
|
1720 else |
|
1721 str = strcat (str(1:s(i) - 1), '/', |
|
1722 str(e(i)+b1(1) + 1:e(i)+b2(1)-1), '{}', |
|
1723 str(e(i) + b2(1) + 1:end)); |
|
1724 endif |
|
1725 elseif(strcmp (f, "fontsize")) |
|
1726 b1 = strfind(str(e(i) + 1:end),'{'); |
|
1727 b2 = strfind(str(e(i) + 1:end),'}'); |
|
1728 if (isempty(b1) || isempty(b2)) |
|
1729 warning ('syntax error in \fontname argument'); |
|
1730 else |
|
1731 str = strcat (str(1:s(i) - 1), '/=', |
|
1732 str(e(i)+b1(1) + 1:e(i)+b2(1)-1), '{}', |
|
1733 str(e(i) + b2(1) + 1:end)); |
|
1734 endif |
|
1735 else |
|
1736 ## Last desperate attempt to treat the symbol. Look for things |
|
1737 ## like \pix, that should be translated to the symbol Pi and x |
|
1738 for j = 1 : length (flds) |
|
1739 if (strncmp (flds{j}, f, length (flds{j}))) |
|
1740 g = getfield(sym, flds{j}); |
|
1741 ## FIXME The symbol font doesn't seem to support bold or italic |
|
1742 ##if (bld) |
|
1743 ## if (it) |
|
1744 ## g = regexprep (g, '/Symbol', '/Symbol-bolditalic'); |
|
1745 ## else |
|
1746 ## g = regexprep (g, '/Symbol', '/Symbol-bold'); |
|
1747 ## endif |
|
1748 ##elseif (it) |
|
1749 ## g = regexprep (g, '/Symbol', '/Symbol-italic'); |
|
1750 ##endif |
|
1751 str = strcat (str(1:s(i) - 1), g, |
|
1752 str(s(i) + length (flds{j}) + 1:end)); |
|
1753 break; |
|
1754 endif |
|
1755 endfor |
|
1756 endif |
|
1757 endif |
|
1758 endfor |
|
1759 |
|
1760 ## Prepend @ to things things like _0^x or _{-100}^{100} for alignment |
|
1761 ## But need to put the shorter of the two arguments first. Carful of |
|
1762 ## nested {} and unprinted characters when defining shortest.. Don't |
|
1763 ## have to worry about things like ^\theta as they are already converted to |
|
1764 ## ^{/Symbol q}. |
|
1765 |
|
1766 ## FIXME.. This is a mess... Is it worth it just for a "@" character? |
|
1767 |
|
1768 [s, m] = regexp(str,'[_\^]','start','matches'); |
|
1769 i = 1; |
|
1770 p = 0; |
|
1771 while (i < length (s)) |
|
1772 if (i < length(s)) |
|
1773 if (str(s(i) + p + 1) == "{") |
|
1774 s1 = strfind(str(s(i) + p + 2:end),'{'); |
|
1775 si = 1; |
|
1776 l1 = strfind(str(s(i) + p + 1:end),'}'); |
|
1777 li = 1; |
|
1778 while (li <= length (l1) && si <= length (s1)) |
|
1779 if (l1(li) < s1(si)) |
|
1780 if (li == si) |
|
1781 break; |
|
1782 endif |
|
1783 li++; |
|
1784 else |
|
1785 si++; |
|
1786 endif |
|
1787 endwhile |
|
1788 l1 = l1 (min (length(l1), si)); |
|
1789 if (s(i) + l1 + 1 == s(i+1)) |
|
1790 if (str(s(i + 1) + p + 1) == "{") |
|
1791 s2 = strfind(str(s(i + 1) + p + 2:end),'{'); |
|
1792 si = 1; |
|
1793 l2 = strfind(str(s(i + 1) + p + 1:end),'}'); |
|
1794 li = 1; |
|
1795 while (li <= length (l2) && si <= length (s2)) |
|
1796 if (l2(li) < s2(si)) |
|
1797 if (li == si) |
|
1798 break; |
|
1799 endif |
|
1800 li++; |
|
1801 else |
|
1802 si++; |
|
1803 endif |
|
1804 endwhile |
|
1805 l2 = l2 (min (length(l2), si)); |
|
1806 if (length_string (str(s(i)+p+2:s(i)+p+l1-1)) <= |
|
1807 length_string(str(s(i+1)+p+2:s(i+1)+p+l2-1))) |
|
1808 ## shortest already first! |
|
1809 str = strcat (str(1:s(i)+p-1), "@", str(s(i)+p:end)); |
|
1810 else |
|
1811 ## Have to swap sub/super-script to get shortest first |
|
1812 str = strcat (str(1:s(i)+p-1), "@", str(s(i+1)+p:s(i+1)+p+l2), |
|
1813 str(s(i)+p:s(i)+p+l1), str(s(i+1)+p+l2+1:end)); |
|
1814 endif |
|
1815 else |
|
1816 ## Have to swap sub/super-script to get shortest first |
|
1817 str = strcat (str(1:s(i)+p-1), "@", str(s(i+1)+p:s(i+1)+p+1), |
|
1818 str(s(i)+p:s(i)+p+l1), str(s(i+1)+p+2:end)); |
|
1819 endif |
|
1820 i += 2; |
|
1821 p ++; |
|
1822 else |
|
1823 i++; |
|
1824 endif |
|
1825 else |
|
1826 if (s(i+1) == s(i) + 2) |
|
1827 ## shortest already first! |
|
1828 str = strcat (str(1:s(i)+p-1), "@", str(s(i)+p:end)); |
|
1829 p ++; |
|
1830 i += 2; |
|
1831 else |
|
1832 i ++; |
|
1833 endif |
|
1834 endif |
|
1835 else |
|
1836 i ++; |
|
1837 endif |
|
1838 endwhile |
|
1839 |
|
1840 endfunction |
|
1841 |
|
1842 function l = length_string (s) |
|
1843 l = length (s) - length (strfind(s,'{')) - length (strfind(s,'}')); |
|
1844 m = regexp (s, '/([\w\-]+|[\w\-]+=\d+)', 'matches'); |
|
1845 if (!isempty (m)) |
|
1846 l = l - sum (cellfun (@length, m)); |
|
1847 endif |
|
1848 endfunction |
|
1849 |
|
1850 function sym = __setup_sym_table__ () |
|
1851 ## Setup the translation table for TeX to gnuplot enhanced mode. |
|
1852 sym.forall = '{/Symbol \042}'; |
|
1853 sym.exists = '{/Symbol \044}'; |
|
1854 sym.ni = '{/Symbol \047}'; |
|
1855 sym.cong = '{/Symbol \100}'; |
|
1856 sym.Delta = '{/Symbol D}'; |
|
1857 sym.Phi = '{/Symbol F}'; |
|
1858 sym.Gamma = '/Symbol G}'; |
7190
|
1859 sym.vartheta = '{/Symbol J}'; |
7189
|
1860 sym.Lambda = '{/Symbol L}'; |
|
1861 sym.Pi = '{/Symbol P}'; |
|
1862 sym.Theta = '{/Symbol Q}'; |
|
1863 sym.Sigma = '{/Symbol S}'; |
|
1864 sym.varsigma = '{/Symbol V}'; |
|
1865 sym.Omega = '{/Symbol O}'; |
|
1866 sym.Xi = '{/Symbol X}'; |
|
1867 sym.Psi = '{/Symbol Y}'; |
|
1868 sym.perp = '{/Symbol \136}'; |
|
1869 sym.alpha = '{/Symbol a}'; |
|
1870 sym.beta = '{/Symbol b}'; |
|
1871 sym.chi = '{/Symbol c}'; |
|
1872 sym.delta = '{/Symbol d}'; |
|
1873 sym.epsilon = '{/Symbol e}'; |
|
1874 sym.phi = '{/Symbol f}'; |
|
1875 sym.gamma = '/Symbol g}'; |
|
1876 sym.eta = '{/Symbol h}'; |
|
1877 sym.iota = '{/Symbol i}'; |
|
1878 sym.kappa = '{/Symbol k}'; |
|
1879 sym.lambda = '{/Symbol l}'; |
|
1880 sym.mu = '{/Symbol m}'; |
|
1881 sym.nu = '{/Symbol n}'; |
|
1882 sym.o = '{/Symbol o}'; |
|
1883 sym.pi = '{/Symbol p}'; |
|
1884 sym.theta = '{/Symbol q}'; |
|
1885 sym.rho = '{/Symbol r}'; |
|
1886 sym.sigma = '{/Symbol s}'; |
|
1887 sym.tau = '{/Symbol t}'; |
|
1888 sym.upsilon = '{/Symbol u}'; |
|
1889 sym.varpi = '{/Symbol v}'; |
|
1890 sym.omega = '{/Symbol w}'; |
|
1891 sym.xi = '{/Symbol x}'; |
|
1892 sym.psi = '{/Symbol y}'; |
|
1893 sym.zeta = '{/Symbol z}'; |
|
1894 sym.sim = '{/Symbol \176}'; |
|
1895 sym.Upsilon = '{/Symbol \241}'; |
|
1896 sym.prime = '{/Symbol \242}'; |
|
1897 sym.leq = '{/Symbol \243}'; |
|
1898 sym.infty = '{/Symbol \245}'; |
|
1899 sym.clubsuit = '{/Symbol \247}'; |
|
1900 sym.diamondsuit = '{/Symbol \250}'; |
|
1901 sym.heartsuit = '{/Symbol \251}'; |
|
1902 sym.spadesuit = '{/Symbol \252}'; |
|
1903 sym.leftrightarrow = '{/Symbol \253}'; |
|
1904 sym.leftarrow = '{/Symbol \254}'; |
|
1905 sym.uparrow = '{/Symbol \255}'; |
|
1906 sym.rightarrow = '{/Symbol \256}'; |
|
1907 sym.downarrow = '{/Symbol \257}'; |
|
1908 sym.circ = '{/Symbol \260}'; |
|
1909 sym.pm = '{/Symbol \261}'; |
|
1910 sym.geq = '{/Symbol \263}'; |
|
1911 sym.times = '{/Symbol \264}'; |
|
1912 sym.propto = '{/Symbol \265}'; |
|
1913 sym.partial = '{/Symbol \266}'; |
|
1914 sym.bullet = '{/Symbol \267}'; |
|
1915 sym.div = '{/Symbol \270}'; |
|
1916 sym.neq = '{/Symbol \271}'; |
|
1917 sym.equiv = '{/Symbol \272}'; |
|
1918 sym.approx = '{/Symbol \273}'; |
|
1919 sym.ldots = '{/Symbol \274}'; |
|
1920 sym.mid = '{/Symbol \275}'; |
|
1921 sym.aleph = '{/Symbol \300}'; |
|
1922 sym.Im = '{/Symbol \301}'; |
|
1923 sym.Re = '{/Symbol \302}'; |
|
1924 sym.wp = '{/Symbol \303}'; |
|
1925 sym.otimes = '{/Symbol \304}'; |
|
1926 sym.oplus = '{/Symbol \305}'; |
|
1927 sym.oslash = '{/Symbol \306}'; |
|
1928 sym.cap = '{/Symbol \307}'; |
|
1929 sym.cup = '{/Symbol \310}'; |
|
1930 sym.supset = '{/Symbol \311}'; |
|
1931 sym.supseteq = '{/Symbol \312}'; |
|
1932 sym.subset = '{/Symbol \314}'; |
|
1933 sym.subseteq = '{/Symbol \315}'; |
|
1934 sym.in = '{/Symbol \316}'; |
|
1935 sym.langle = '{/Symbol \320}'; |
|
1936 sym.rangle = '{/Symbol \320}'; |
|
1937 sym.nabla = '{/Symbol \321}'; |
|
1938 sym.surd = '{/Symbol \326}'; |
|
1939 sym.cdot = '{/Symbol \327}'; |
|
1940 sym.neg = '{/Symbol \330}'; |
|
1941 sym.wedge = '{/Symbol \331}'; |
|
1942 sym.vee = '{/Symbol \332}'; |
|
1943 sym.copyright = '{/Symbol \343}'; |
|
1944 sym.rfloor = '{/Symbol \353}'; |
|
1945 sym.lceil = '{/Symbol \351}'; |
|
1946 sym.lfloor = '{/Symbol \373}'; |
|
1947 sym.rceil = '{/Symbol \371}'; |
|
1948 sym.int = '{/Symbol \362}'; |
|
1949 endfunction |
|
1950 |
|
1951 function [pos, orient, sz, origin, mirr] = gnuplot_postion_colorbox (pos, cbox) |
|
1952 ## This is an emprically derived function that |
|
1953 |
|
1954 if (strncmp (cbox, "north", 5) || strncmp (cbox, "south", 5)) |
|
1955 scl = pos([2,4]); |
|
1956 else |
|
1957 scl = pos([1,3]); |
|
1958 endif |
|
1959 |
|
1960 if (length(cbox) > 7 && strncmp (cbox(end-6:end), "outside", 7)) |
|
1961 scl(2) -= 0.2 * scl(2); |
|
1962 if (strncmp (cbox, "west", 4) || strncmp (cbox, "south", 5)) |
|
1963 scl(1) += 0.2 * scl(2); |
|
1964 endif |
|
1965 endif |
|
1966 |
|
1967 switch (cbox) |
|
1968 case "northoutside" |
|
1969 sz = pos(3:4) - 0.08; |
|
1970 origin = [0.05, 0.06] + [0.00, 0.88] .* sz + pos(1:2); |
|
1971 mirr = true; |
|
1972 orient = "horizontal"; |
|
1973 case "north" |
|
1974 sz = pos(3:4) - 0.16; |
|
1975 origin = [0.09, 0.09] + [0.00, 0.94] .* sz + pos(1:2); |
|
1976 mirr = false; |
|
1977 orient = "horizontal"; |
|
1978 case "southoutside" |
|
1979 sz = pos(3:4) - 0.08; |
|
1980 origin = [0.05, 0.06] + [0.00, 0.00] .* sz + pos(1:2); |
|
1981 mirr = false; |
|
1982 orient = "horizontal"; |
|
1983 case "south" |
|
1984 sz = pos(3:4) - 0.16; |
|
1985 origin = [0.08, 0.09] + [0.03, 0.05] .* sz + pos(1:2); |
|
1986 mirr = true; |
|
1987 orient = "horizontal"; |
|
1988 case "eastoutside" |
|
1989 sz = pos(3:4) - 0.08; |
|
1990 origin = [0.00, 0.06] + [0.94, 0.00] .* sz + pos(1:2); |
|
1991 mirr = false; |
|
1992 orient = "vertical"; |
|
1993 case "east" |
|
1994 sz = pos(3:4) - 0.16; |
|
1995 origin = [0.09, 0.10] + [0.91, 0.01] .* sz + pos(1:2); |
|
1996 mirr = true; |
|
1997 orient = "vertical"; |
|
1998 case "westoutside" |
|
1999 sz = pos(3:4) - 0.08; |
|
2000 origin = [0.00, 0.06] + [0.06, 0.00] .* sz + pos(1:2); |
|
2001 mirr = true; |
|
2002 orient = "vertical"; |
|
2003 case "west" |
|
2004 sz = pos(3:4) - 0.16; |
|
2005 origin = [0.06, 0.09] + [0.04, 0.03] .* sz + pos(1:2); |
|
2006 mirr = false; |
|
2007 orient = "vertical"; |
|
2008 endswitch |
|
2009 |
|
2010 if (strncmp (cbox, "north", 5) || strncmp (cbox, "south", 5)) |
|
2011 sz = sz .* [1, 0.07]; |
|
2012 pos([2,4]) = scl; |
|
2013 else |
|
2014 sz = sz .* [0.07, 1]; |
|
2015 pos([1,3]) = scl; |
|
2016 endif |
|
2017 |
|
2018 endfunction |