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