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