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