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