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