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