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