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