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