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