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