Mercurial > hg > octave-nkf
annotate scripts/plot/__go_draw_axes__.m @ 11651:74de76325d12 release-3-0-x
more xGELSD workspace fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 15 Feb 2008 18:55:45 -0500 |
parents | 2be7477f470a |
children | 4bfe1ab20e99 |
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 |
27 axis_obj = get (h); | |
28 | |
29 parent_figure_obj = get (axis_obj.parent); | |
30 | |
6413 | 31 persistent have_newer_gnuplot ... |
32 = compare_versions (__gnuplot_version__ (), "4.0", ">"); | |
6405 | 33 |
34 ## Set axis properties here? | |
7191 | 35 pos = [0, 0, 1, 1]; |
7240 | 36 if (strcmp (axis_obj.activepositionproperty, "outerposition")) |
37 ymirror = true; | |
38 if (! isempty (axis_obj.outerposition)) | |
39 pos = axis_obj.outerposition; | |
40 endif | |
41 else | |
7206 | 42 ymirror = false; |
7240 | 43 if (! isempty (axis_obj.position)) |
44 pos = axis_obj.position; | |
45 fprintf (plot_stream, "set tmargin 0;\n"); | |
46 fprintf (plot_stream, "set bmargin 0;\n"); | |
47 fprintf (plot_stream, "set lmargin 0;\n"); | |
48 fprintf (plot_stream, "set rmargin 0;\n"); | |
49 endif | |
6405 | 50 endif |
51 | |
7189 | 52 if (! strcmp (axis_obj.__colorbar__, "none")) |
53 [pos, cbox_orient, cbox_size, cbox_origin, cbox_mirror] = ... | |
54 gnuplot_postion_colorbox (pos, axis_obj.__colorbar__); | |
55 endif | |
56 | |
57 fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2)); | |
58 fprintf (plot_stream, "set size %.15g, %.15g;\n", pos(3), pos(4)); | |
59 | |
6758 | 60 if (strcmpi (axis_obj.dataaspectratiomode, "manual")) |
6405 | 61 r = axis_obj.dataaspectratio; |
6914 | 62 fprintf (plot_stream, "set size ratio %.15g;\n", -r(2)/r(1)); |
6405 | 63 else |
64 fputs (plot_stream, "set size noratio;\n"); | |
65 endif | |
66 | |
11636
2be7477f470a
Fix colorbar with contours
David Bateman <dbateman@free.fr>
parents:
11635
diff
changeset
|
67 fputs (plot_stream, "set pm3d implicit;\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 | |
11615 | 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")) |
11615 | 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 |
11615 | 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")) |
11615 | 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 |
11615 | 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 | |
11615 | 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"); |
11635
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
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 | |
11635
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
341 if (strcmp (obj.cdatamapping, "direct")) |
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
342 cdatadirect = true; |
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
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; | |
11635
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
508 if (strcmp (obj.cdatamapping, "direct")) |
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
509 cdatadirect = true; |
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
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 | |
704 if (isfield (obj, "marker")) | |
705 if (isfield (obj, "marker")) | |
706 switch (obj.marker) | |
707 case "+" | |
708 pt = "pt 1"; | |
709 case "o" | |
710 pt = "pt 6"; | |
711 case "*" | |
712 pt = "pt 3"; | |
713 case "." | |
714 pt = "pt 0"; | |
715 case "x" | |
716 pt = "pt 2"; | |
717 case {"square", "s"} | |
718 pt = "pt 5"; | |
719 case {"diamond", "d"} | |
720 pt = "pt 13"; | |
721 case "^" | |
722 pt = "pt 9"; | |
723 case "v" | |
724 pt = "pt 11"; | |
725 case ">" | |
726 pt = "pt 8"; | |
727 case "<" | |
728 pt = "pt 10"; | |
729 case {"pentagram", "p"} | |
730 pt = "pt 4"; | |
731 case {"hexagram", "h"} | |
732 pt = "pt 12"; | |
733 case "none" | |
734 pt = ""; | |
735 otherwise | |
736 pt = ""; | |
737 endswitch | |
738 endif | |
739 else | |
740 pt = ""; | |
741 endif | |
742 | |
743 style = "lines"; | |
744 if (isempty (lt)) | |
745 if (! isempty (pt)) | |
746 style = "points"; | |
747 endif | |
748 elseif (! isempty (pt)) | |
749 style = "linespoints"; | |
750 endif | |
751 | |
752 if (isfield (obj, "markersize")) | |
753 if (length (mdat) == nc) | |
754 m = mdat(i); | |
755 else | |
756 m = mdat; | |
757 endif | |
758 if (! strcmpi (style, "lines")) | |
759 if (have_newer_gnuplot) | |
760 ps = sprintf("pointsize %f", m); | |
761 else | |
762 ps = sprintf("ps %f", m); | |
763 endif | |
764 else | |
765 ps = ""; | |
766 endif | |
767 else | |
768 ps = ""; | |
769 endif | |
770 | |
7020 | 771 if (have_newer_gnuplot) |
7269 | 772 if (mono) |
773 colorspec = ""; | |
774 else | |
775 colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", | |
776 round (255*color)); | |
777 endif | |
7317 | 778 withclause{data_idx} = sprintf ("with %s %s %s %s %s", |
779 style, pt, lt, ps, colorspec); | |
7020 | 780 else |
781 if (isequal (color, [0,0,0])) | |
782 typ = -1; | |
783 elseif (isequal (color, [1,0,0])) | |
784 typ = 1; | |
785 elseif (isequal (color, [0,1,0])) | |
786 typ = 2; | |
787 elseif (isequal (color, [0,0,1])) | |
788 typ = 3; | |
789 elseif (isequal (color, [1,0,1])) | |
790 typ = 4; | |
791 elseif (isequal (color, [0,1,1])) | |
792 typ = 5; | |
793 elseif (isequal (color, [1,1,1])) | |
794 typ = -1; | |
795 elseif (isequal (color, [1,1,0])) | |
796 typ = 7; | |
797 else | |
798 typ = -1; | |
799 endif | |
7189 | 800 withclause{data_idx} = sprintf ("with %s %s %s lt %d", |
801 style, pt, ps, typ); | |
7020 | 802 endif |
6790 | 803 |
7316 | 804 if (nd == 3) |
7170 | 805 if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol)) |
806 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ... | |
807 [zcol; zcol(1)]]'; | |
808 else | |
809 data{data_idx} = [xcol, ycol, zcol]'; | |
810 endif | |
811 usingclause{data_idx} = "using ($1):($2):($3)"; | |
7020 | 812 else |
7170 | 813 if (! isnan (xcol) && ! isnan (ycol)) |
814 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]'; | |
815 else | |
816 data{data_idx} = [xcol, ycol]'; | |
817 endif | |
818 usingclause{data_idx} = "using ($1):($2)"; | |
7020 | 819 endif |
6885 | 820 endif |
7020 | 821 endfor |
6790 | 822 |
6405 | 823 case "surface" |
7271 | 824 view_map = true; |
7110 | 825 if (! (strncmp (obj.edgecolor, "none", 4) |
826 && strncmp (obj.facecolor, "none", 4))) | |
7109 | 827 data_idx++; |
828 is_image_data(data_idx) = false; | |
829 parametric(data_idx) = false; | |
7119 | 830 have_cdata(data_idx) = true; |
7170 | 831 [style, typ, with] = do_linestyle_command (obj, data_idx, |
7269 | 832 mono, plot_stream); |
7109 | 833 if (isempty (obj.keylabel)) |
834 titlespec{data_idx} = "title \"\""; | |
835 else | |
7189 | 836 tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "keylabel", have_newer_gnuplot)); |
7109 | 837 titlespec{data_idx} = strcat ("title \"", tmp, "\""); |
838 endif | |
839 usingclause{data_idx} = ""; | |
840 if (have_newer_gnuplot || isnan (typ)) | |
7318 | 841 withclause{data_idx} = sprintf ("with pm3d linestyle %d", |
842 data_idx); | |
6405 | 843 else |
7318 | 844 withclause{data_idx} = sprintf ("with pm3d linetype %d %s", |
845 typ, with); | |
7109 | 846 endif |
847 | |
848 xdat = obj.xdata; | |
849 ydat = obj.ydata; | |
850 zdat = obj.zdata; | |
851 cdat = obj.cdata; | |
7110 | 852 |
7109 | 853 err = false; |
854 if (! size_equal(zdat, cdat)) | |
6405 | 855 err = true; |
7109 | 856 endif |
857 if (isvector (xdat) && isvector (ydat) && ismatrix (zdat)) | |
7110 | 858 if (rows (zdat) == length (ydat) |
859 && columns (zdat) == length (xdat)) | |
7109 | 860 [xdat, ydat] = meshgrid (xdat, ydat); |
861 else | |
862 err = true; | |
863 endif | |
864 elseif (ismatrix (xdat) && ismatrix (ydat) && ismatrix (zdat)) | |
7292 | 865 if (! size_equal (xdat, ydat, zdat)) |
7109 | 866 err = true; |
867 endif | |
868 else | |
869 err = true; | |
870 endif | |
871 if (err) | |
872 error ("__go_draw_axes__: invalid grid data"); | |
6405 | 873 endif |
7109 | 874 xlen = columns (zdat); |
875 ylen = rows (zdat); | |
876 if (xlen == columns (xdat) && xlen == columns (ydat) | |
877 && ylen == rows (xdat) && ylen == rows (ydat)) | |
878 len = 4 * xlen; | |
879 zz = zeros (ylen, len); | |
880 k = 1; | |
881 for kk = 1:4:len | |
882 zz(:,kk) = xdat(:,k); | |
883 zz(:,kk+1) = ydat(:,k); | |
884 zz(:,kk+2) = zdat(:,k); | |
885 zz(:,kk+3) = cdat(:,k); | |
886 k++; | |
887 endfor | |
7170 | 888 data{data_idx} = zz.'; |
7109 | 889 endif |
890 usingclause{data_idx} = "using ($1):($2):($3):($4)"; | |
7316 | 891 ## fputs (plot_stream, "unset parametric;\n"); |
7109 | 892 |
7119 | 893 ## Interpolation does not work for flat surfaces (e.g. pcolor) |
894 ## and color mapping --> currently set empty. | |
895 interp_str = ""; | |
896 flat_interp_face = (strncmp (obj.facecolor, "flat", 4) | |
897 || strncmp (obj.facecolor, "interp", 6)); | |
898 flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4) | |
899 || strncmp (obj.edgecolor, "interp", 6)); | |
7154 | 900 |
901 facecolor_none_or_white = (strncmp (obj.facecolor, "none", 4) | |
902 || (isnumeric (obj.facecolor) | |
903 && all (obj.facecolor == 1))); | |
7149 | 904 if (strncmp (obj.facecolor, "none", 4)) |
7318 | 905 hidden_removal = false; |
7175 | 906 else |
7318 | 907 if (isnan (hidden_removal)) |
908 hidden_removal = true; | |
909 endif | |
7149 | 910 endif |
7318 | 911 |
912 if (flat_interp_edge && facecolor_none_or_white) | |
7189 | 913 withclause{data_idx} = "with line palette"; |
7119 | 914 endif |
7109 | 915 |
7189 | 916 if (have_newer_gnuplot) |
917 dord = "depthorder"; | |
918 else | |
919 dord = ""; | |
920 endif | |
7109 | 921 |
7318 | 922 if (flat_interp_face && strncmp (obj.edgecolor, "flat", 4)) |
923 fprintf (plot_stream, "set pm3d explicit at s %s %s corners2color c3;\n", | |
7189 | 924 interp_str, dord); |
7318 | 925 elseif (!facecolor_none_or_white) |
7119 | 926 if (strncmp (obj.edgecolor, "none", 4)) |
7318 | 927 fprintf (plot_stream, "set pm3d explicit at s %s corners2color c3;\n", |
7189 | 928 interp_str, dord); |
7109 | 929 else |
7119 | 930 edgecol = obj.edgecolor; |
931 if (ischar (obj.edgecolor)) | |
932 edgecol = [0,0,0]; | |
933 endif | |
7318 | 934 fprintf (plot_stream, "set pm3d explicit at s hidden3d %d %s %s corners2color c3;\n", |
7189 | 935 data_idx, interp_str, dord); |
7119 | 936 |
937 if (have_newer_gnuplot) | |
7269 | 938 if (mono) |
939 colorspec = ""; | |
940 else | |
941 colorspec = sprintf ("linecolor rgb \"#%02x%02x%02x\"", | |
942 round (255*edgecol)); | |
943 endif | |
7110 | 944 fprintf (plot_stream, |
7269 | 945 "set style line %d %s lw %f;\n", |
946 data_idx, colorspec, obj.linewidth); | |
7119 | 947 else |
948 if (isequal (edgecol, [0,0,0])) | |
949 typ = -1; | |
950 elseif (isequal (edgecol, [1,0,0])) | |
951 typ = 1; | |
952 elseif (isequal (edgecol, [0,1,0])) | |
953 typ = 2; | |
954 elseif (isequal (edgecol, [0,0,1])) | |
955 typ = 3; | |
956 elseif (isequal (edgecol, [1,0,1])) | |
957 typ = 4; | |
958 elseif (isequal (edgecol, [0,1,1])) | |
959 typ = 5; | |
960 elseif (isequal (edgecol, [1,1,1])) | |
961 typ = -1; | |
962 elseif (isequal (edgecol, [1,1,0])) | |
963 typ = 7; | |
964 else | |
965 typ = -1; | |
966 endif | |
967 fprintf (plot_stream, | |
968 "set style line %d lt %d lw %f;\n", | |
969 data_idx, typ, obj.linewidth); | |
970 endif | |
7109 | 971 endif |
7119 | 972 endif |
6405 | 973 endif |
974 | |
975 case "text" | |
7189 | 976 [label, f, s] = __maybe_munge_text__ (enhanced, obj, "string", |
977 have_newer_gnuplot); | |
7257 | 978 if (strcmp (f, "*")) |
979 fontspec = ""; | |
980 else | |
981 fontspec = sprintf ("font \"%s,%d\"", f, s); | |
982 endif | |
6405 | 983 lpos = obj.position; |
984 halign = obj.horizontalalignment; | |
6724 | 985 angle = obj.rotation; |
6752 | 986 units = obj.units; |
6829 | 987 color = obj.color; |
6758 | 988 if (strcmpi (units, "normalized")) |
6752 | 989 units = "graph"; |
990 else | |
991 units = ""; | |
992 endif | |
993 | |
6829 | 994 if (isnumeric (color)) |
7269 | 995 colorspec = get_text_colorspec (color, mono); |
6829 | 996 endif |
997 | |
6405 | 998 if (nd == 3) |
6724 | 999 fprintf (plot_stream, |
11615 | 1000 "set label \"%s\" at %s %.15g,%.15g,%.15g %s rotate by %f %s %s front %s;\n", |
7162 | 1001 undo_string_escapes (label), units, lpos(1), |
11615 | 1002 lpos(2), lpos(3), halign, angle, fontspec, |
1003 __do_enhanced_option__ (enhanced, obj), colorspec); | |
6405 | 1004 else |
7162 | 1005 fprintf (plot_stream, |
11615 | 1006 "set label \"%s\" at %s %.15g,%.15g %s rotate by %f %s %s front %s;\n", |
7162 | 1007 undo_string_escapes (label), units, |
11615 | 1008 lpos(1), lpos(2), halign, angle, fontspec, |
1009 __do_enhanced_option__ (enhanced, obj), colorspec); | |
6405 | 1010 endif |
1011 | |
1012 otherwise | |
1013 error ("__go_draw_axes__: unknown object class, %s", | |
1014 obj.type); | |
1015 endswitch | |
1016 | |
1017 endfor | |
1018 | |
7175 | 1019 if (isnan(hidden_removal) || hidden_removal) |
7149 | 1020 fputs (plot_stream, "set hidden3d;\n"); |
1021 else | |
1022 fputs (plot_stream, "unset hidden3d;\n"); | |
1023 endif | |
1024 | |
7152 | 1025 have_data = (! (isempty (data) || any (cellfun (@isempty, data)))); |
6405 | 1026 |
7222 | 1027 if (isempty (xlim)) |
1028 return; | |
6405 | 1029 endif |
6758 | 1030 if (strcmpi (axis_obj.xdir, "reverse")) |
6405 | 1031 xdir = "reverse"; |
1032 else | |
1033 xdir = "noreverse"; | |
1034 endif | |
7115 | 1035 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", |
1036 xaxisloc, xlim, xdir); | |
6405 | 1037 |
7222 | 1038 if (isempty (ylim)) |
1039 return; | |
6405 | 1040 endif |
6758 | 1041 if (strcmpi (axis_obj.ydir, "reverse")) |
6405 | 1042 ydir = "reverse"; |
1043 else | |
1044 ydir = "noreverse"; | |
1045 endif | |
7110 | 1046 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", |
1047 yaxisloc, ylim, ydir); | |
6405 | 1048 |
7119 | 1049 if (nd == 3) |
7222 | 1050 if (isempty (zlim)) |
1051 return; | |
6405 | 1052 endif |
6758 | 1053 if (strcmpi (axis_obj.zdir, "reverse")) |
6405 | 1054 zdir = "reverse"; |
1055 else | |
1056 zdir = "noreverse"; | |
1057 endif | |
6942 | 1058 fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir); |
6405 | 1059 endif |
7110 | 1060 |
11635
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
1061 cmap = parent_figure_obj.colormap; |
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
1062 cmap_sz = rows(cmap); |
7189 | 1063 if (! any (isinf (clim))) |
11635
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
1064 if (cdatadirect) |
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
1065 fprintf (plot_stream, "set cbrange [1:%d];\n", cmap_sz); |
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
1066 else |
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
1067 fprintf (plot_stream, "set cbrange [%g:%g];\n", clim); |
e08d2fff0d58
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
11622
diff
changeset
|
1068 endif |
7189 | 1069 endif |
1070 | |
6758 | 1071 if (strcmpi (axis_obj.box, "on")) |
7119 | 1072 if (nd == 3) |
6405 | 1073 fputs (plot_stream, "set border 4095;\n"); |
1074 else | |
1075 fputs (plot_stream, "set border 431;\n"); | |
1076 endif | |
1077 else | |
7119 | 1078 if (nd == 3) |
6405 | 1079 fputs (plot_stream, "set border 895;\n"); |
1080 else | |
7320 | 1081 if (strcmpi (axis_obj.yaxislocation, "right")) |
1082 fputs (plot_stream, "unset ytics; set y2tics nomirror\n"); | |
1083 if (strcmpi (axis_obj.xaxislocation, "top")) | |
1084 fputs (plot_stream, "unset xtics; set x2tics nomirror\n"); | |
1085 fputs (plot_stream, "set border 12;\n"); | |
1086 else | |
1087 fputs (plot_stream, "unset x2tics; set xtics nomirror\n"); | |
1088 fputs (plot_stream, "set border 9;\n"); | |
1089 endif | |
1090 else | |
1091 fputs (plot_stream, "unset y2tics; set ytics nomirror\n"); | |
1092 if (strcmpi (axis_obj.xaxislocation, "top")) | |
1093 fputs (plot_stream, "unset xtics; set x2tics nomirror\n"); | |
1094 fputs (plot_stream, "set border 6;\n"); | |
1095 else | |
1096 fputs (plot_stream, "unset x2tics; set xtics nomirror\n"); | |
1097 fputs (plot_stream, "set border 3;\n"); | |
1098 endif | |
1099 endif | |
6405 | 1100 endif |
1101 endif | |
1102 | |
7060 | 1103 if (strcmpi (axis_obj.visible, "off")) |
1104 fputs (plot_stream, "unset border; unset tics\n"); | |
1105 endif | |
1106 | |
6758 | 1107 if (strcmpi (axis_obj.key, "on")) |
1108 if (strcmpi (axis_obj.keybox, "on")) | |
6405 | 1109 box = "box"; |
1110 else | |
1111 box = "nobox"; | |
1112 endif | |
1113 inout = "inside"; | |
6977 | 1114 keypos = axis_obj.keypos; |
1115 if (ischar (keypos)) | |
1116 keypos = lower (keypos); | |
1117 keyout = findstr (keypos, "outside"); | |
1118 if (! isempty (keyout)) | |
1119 inout = "outside"; | |
7119 | 1120 keypos = keypos(1:keyout-1); |
6977 | 1121 endif |
1122 endif | |
1123 switch (keypos) | |
6405 | 1124 case -1 |
6977 | 1125 pos = "right top"; |
6405 | 1126 inout = "outside"; |
1127 case 1 | |
1128 pos = "right top"; | |
1129 case 2 | |
1130 pos = "left top"; | |
1131 case 3 | |
1132 pos = "left bottom"; | |
6977 | 1133 case {4, 0} |
6405 | 1134 pos = "right bottom"; |
6977 | 1135 case "north" |
1136 pos = "center top"; | |
1137 case "south" | |
1138 pos = "center bottom"; | |
1139 case "east" | |
1140 pos = "right center"; | |
1141 case "west" | |
1142 pos = "left center"; | |
1143 case "northeast" | |
1144 pos = "right top"; | |
1145 case "northwest" | |
1146 pos = "left top"; | |
1147 case "southeast" | |
1148 pos = "right bottom"; | |
1149 case "southwest" | |
1150 pos = "left bottom"; | |
1151 case "best" | |
1152 pos = ""; | |
1153 warning ("legend: 'Best' not yet implemented for location specifier.\n"); | |
1154 ## least conflict with data in plot | |
1155 ## least unused space outside plot | |
6405 | 1156 otherwise |
1157 pos = ""; | |
1158 endswitch | |
1159 if (! have_newer_gnuplot) | |
1160 inout = ""; | |
1161 endif | |
1162 fprintf (plot_stream, "set key %s %s %s;\n", inout, pos, box); | |
1163 else | |
1164 fputs (plot_stream, "unset key;\n"); | |
1165 endif | |
1166 | |
1167 fputs (plot_stream, "set style data lines;\n"); | |
1168 | |
1169 if (! use_gnuplot_for_images) | |
1170 for i = 1:ximg_data_idx | |
1171 view_fcn (xlim, ylim, ximg_data{i}, view_zoom, view_cmd); | |
1172 endfor | |
1173 endif | |
1174 | |
7189 | 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"); | |
11636
2be7477f470a
Fix colorbar with contours
David Bateman <dbateman@free.fr>
parents:
11635
diff
changeset
|
1184 fwrite (plot_stream, "\n"); |
7189 | 1185 else |
1186 fputs (plot_stream, "set palette defined ("); | |
1187 for i = 1: cmap_sz | |
1188 col = floor(cmap(i, :) * 255); | |
1189 if (i == 1) | |
1190 fputs (plot_stream, sprintf("%d \"#%02X%02X%02X\"", i - 1, | |
1191 col(1), col(2), col(3))); | |
1192 else | |
1193 fputs (plot_stream, sprintf(", %d \"#%02X%02X%02X\"", i - 1, | |
1194 col(1), col(2), col(3))); | |
1195 endif | |
1196 endfor | |
1197 fputs (plot_stream, ");\n"); | |
1198 endif | |
1199 endif | |
1200 | |
1201 if (strcmp (axis_obj.__colorbar__, "none")) | |
1202 fputs (plot_stream, "unset colorbox;\n"); | |
1203 else | |
1204 ## FIXME If cbox_mirror is true we want to invert the tic labels | |
1205 ## but gnuplot doesn't allow that | |
1206 fputs (plot_stream, | |
1207 sprintf ("set colorbox %s user origin %f,%f size %f,%f;\n", | |
1208 cbox_orient, cbox_origin, cbox_size)); | |
1209 endif | |
1210 | |
6405 | 1211 if (have_data) |
1212 if (nd == 2) | |
1213 plot_cmd = "plot"; | |
1214 else | |
1215 plot_cmd = "splot"; | |
1216 rot_x = 90 - axis_obj.view(2); | |
1217 rot_z = axis_obj.view(1); | |
1218 while (rot_z < 0) | |
1219 rot_z += 360; | |
1220 endwhile | |
6461 | 1221 fputs (plot_stream, "set ticslevel 0;\n"); |
7271 | 1222 if (view_map && rot_x == 0 && rot_z == 0) |
1223 fputs (plot_stream, "set view map;\n"); | |
1224 else | |
1225 fprintf (plot_stream, "set view %.15g, %.15g;\n", rot_x, rot_z); | |
1226 endif | |
6405 | 1227 endif |
6611 | 1228 fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd, |
6464 | 1229 usingclause{1}, titlespec{1}, withclause{1}); |
6405 | 1230 for i = 2:data_idx |
6611 | 1231 fprintf (plot_stream, ", \"-\" %s %s %s \\\n", |
6464 | 1232 usingclause{i}, titlespec{i}, withclause{i}); |
6405 | 1233 endfor |
1234 fputs (plot_stream, ";\n"); | |
1235 for i = 1:data_idx | |
6464 | 1236 if (is_image_data(i)) |
1237 fwrite (plot_stream, data{i}, "float32"); | |
1238 else | |
7119 | 1239 __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i), |
1240 have_cdata(i)); | |
6405 | 1241 endif |
1242 endfor | |
6431 | 1243 else |
1244 fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n"); | |
6405 | 1245 endif |
1246 | |
7271 | 1247 ## Needed to allow mouse rotation with pcolor |
1248 if (view_map) | |
1249 fputs (plot_stream, "unset view;\n"); | |
1250 endif | |
1251 | |
6405 | 1252 fflush (plot_stream); |
1253 | |
1254 else | |
1255 print_usage (); | |
7109 | 1256 endif |
6405 | 1257 |
1258 endfunction | |
1259 | |
7269 | 1260 function [style, typ, with] = do_linestyle_command (obj, idx, mono, plot_stream) |
6405 | 1261 |
6413 | 1262 persistent have_newer_gnuplot ... |
1263 = compare_versions (__gnuplot_version__ (), "4.0", ">"); | |
6405 | 1264 |
1265 if (have_newer_gnuplot) | |
1266 fprintf (plot_stream, "set style line %d default;\n", idx); | |
1267 endif | |
1268 fprintf (plot_stream, "set style line %d", idx); | |
1269 | |
1270 found_style = false; | |
6425 | 1271 typ = NaN; |
6465 | 1272 with = ""; |
6405 | 1273 |
6425 | 1274 if (isfield (obj, "color")) |
6405 | 1275 color = obj.color; |
1276 if (isnumeric (color)) | |
6425 | 1277 if (have_newer_gnuplot) |
7269 | 1278 if (! mono) |
1279 fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", | |
1280 round (255*color)); | |
1281 endif | |
6425 | 1282 else |
1283 if (isequal (color, [0,0,0])) | |
1284 typ = -1; | |
1285 elseif (isequal (color, [1,0,0])) | |
1286 typ = 1; | |
1287 elseif (isequal (color, [0,1,0])) | |
1288 typ = 2; | |
1289 elseif (isequal (color, [0,0,1])) | |
1290 typ = 3; | |
1291 elseif (isequal (color, [1,0,1])) | |
1292 typ = 4; | |
1293 elseif (isequal (color, [0,1,1])) | |
1294 typ = 5; | |
1295 elseif (isequal (color, [1,1,1])) | |
1296 typ = 6; | |
1297 elseif (isequal (color, [1,1,0])) | |
1298 typ = 7; | |
1299 else | |
1300 typ = 2; | |
1301 endif | |
1302 endif | |
6405 | 1303 endif |
1304 found_style = true; | |
1305 endif | |
1306 | |
1307 if (isfield (obj, "linestyle")) | |
1308 switch (obj.linestyle) | |
1309 case "-" | |
6415 | 1310 lt = "1"; |
6405 | 1311 case "--" |
6415 | 1312 lt = "2"; |
6405 | 1313 case ":" |
6415 | 1314 lt = "3"; |
6405 | 1315 case "-." |
6415 | 1316 lt = "6"; |
6405 | 1317 case "none" |
1318 lt = ""; | |
1319 otherwise | |
1320 lt = ""; | |
1321 endswitch | |
6843 | 1322 |
1323 ## FIXME -- linetype is currently broken, since it disables the | |
1324 ## gnuplot default dashed and solid linestyles with the only | |
1325 ## benefit of being able to specify '--' and get a single sized | |
1326 ## dashed line of identical dash pattern for all called this way. | |
1327 ## All dash patterns are a subset of "with lines" and none of the | |
1328 ## lt specifications will correctly propagate into the x11 terminal | |
1329 ## or the print command. Therefore, it is currently disabled in | |
1330 ## order to allow print (..., "-dashed") etc. to work correctly. | |
1331 | |
1332 ## if (! isempty (lt)) | |
1333 ## fprintf (plot_stream, " linetype %s", lt); | |
1334 ## found_style = true; | |
1335 ## endif | |
1336 | |
6405 | 1337 else |
1338 lt = ""; | |
1339 endif | |
1340 | |
1341 if (isfield (obj, "linewidth")) | |
6465 | 1342 if (have_newer_gnuplot) |
1343 fprintf (plot_stream, " linewidth %f", obj.linewidth); | |
1344 else | |
1345 with = sprintf ("%s lw %f", with, obj.linewidth); | |
1346 endif | |
6405 | 1347 found_style = true; |
1348 endif | |
1349 | |
1350 if (isfield (obj, "marker")) | |
1351 switch (obj.marker) | |
1352 case "+" | |
1353 pt = "1"; | |
1354 case "o" | |
6413 | 1355 pt = "6"; |
6405 | 1356 case "*" |
1357 pt = "3"; | |
1358 case "." | |
7078 | 1359 pt = "0"; |
6405 | 1360 case "x" |
1361 pt = "2"; | |
1362 case {"square", "s"} | |
1363 pt = "5"; | |
1364 case {"diamond", "d"} | |
1365 pt = "13"; | |
1366 case "^" | |
1367 pt = "9"; | |
1368 case "v" | |
1369 pt = "11"; | |
1370 case ">" | |
1371 pt = "8"; | |
1372 case "<" | |
1373 pt = "10"; | |
1374 case {"pentagram", "p"} | |
1375 pt = "4"; | |
1376 case {"hexagram", "h"} | |
6413 | 1377 pt = "12"; |
6405 | 1378 case "none" |
1379 pt = ""; | |
1380 otherwise | |
1381 pt = ""; | |
1382 endswitch | |
1383 if (! isempty (pt)) | |
6465 | 1384 if (have_newer_gnuplot) |
1385 fprintf (plot_stream, " pointtype %s", pt); | |
1386 else | |
1387 with = sprintf ("%s pt %s", with, pt); | |
1388 endif | |
6405 | 1389 found_style = true; |
1390 endif | |
1391 else | |
1392 pt = ""; | |
1393 endif | |
1394 | |
1395 style = "lines"; | |
1396 if (isempty (lt)) | |
1397 if (! isempty (pt)) | |
1398 style = "points"; | |
1399 endif | |
1400 elseif (! isempty (pt)) | |
1401 style = "linespoints"; | |
1402 endif | |
1403 | |
6465 | 1404 if (isfield (obj, "markersize")) |
1405 if (have_newer_gnuplot) | |
1406 fprintf (plot_stream, " pointsize %f", obj.markersize); | |
1407 else | |
6758 | 1408 if (! strcmpi (style, "lines")) |
6465 | 1409 with = sprintf ("%s ps %f", with, obj.markersize); |
1410 endif | |
1411 endif | |
1412 found_style = true; | |
1413 endif | |
1414 | |
6405 | 1415 if (have_newer_gnuplot && ! found_style) |
1416 fputs (plot_stream, " default"); | |
1417 endif | |
1418 | |
1419 fputs (plot_stream, ";\n"); | |
1420 | |
1421 endfunction | |
6510 | 1422 |
7316 | 1423 function nd = __calc_dimensions__ (obj) |
1424 kids = obj.children; | |
1425 nd = 2; | |
1426 for i = 1:length (kids) | |
1427 obj = get (kids(i)); | |
1428 switch (obj.type) | |
1429 case {"image", "text"} | |
1430 ## ignore as they | |
1431 case {"line", "patch"} | |
1432 if (! isempty (obj.zdata)) | |
1433 nd = 3; | |
1434 endif | |
1435 case "surface" | |
1436 nd = 3; | |
1437 endswitch | |
1438 endfor | |
1439 endfunction | |
1440 | |
7119 | 1441 function __gnuplot_write_data__ (plot_stream, data, nd, parametric, cdata) |
6510 | 1442 |
1443 ## DATA is already transposed. | |
1444 | |
1445 ## FIXME -- this may need to be converted to C++ for speed. | |
1446 | |
6605 | 1447 ## Convert NA elements to normal NaN values because fprintf writes |
1448 ## "NA" and that confuses gnuplot. | |
1449 idx = find (isna (data)); | |
1450 if (any (idx)) | |
1451 data(idx) = NaN; | |
1452 endif | |
1453 | |
6510 | 1454 if (nd == 2) |
1455 nan_elts = find (sum (isnan (data))); | |
6914 | 1456 fmt = strcat (repmat ("%.15g ", 1, rows (data)), "\n"); |
6510 | 1457 if (isempty (nan_elts)) |
1458 fprintf (plot_stream, fmt, data); | |
1459 else | |
1460 n = columns (data); | |
1461 have_nans = true; | |
1462 num_nan_elts = numel (nan_elts); | |
1463 k = 1; | |
1464 for i = 1:n | |
1465 if (have_nans && i == nan_elts(k)) | |
1466 fputs (plot_stream, "\n"); | |
1467 have_nans = ++k <= num_nan_elts; | |
1468 else | |
1469 fprintf (plot_stream, fmt, data(:,i)); | |
1470 endif | |
1471 endfor | |
1472 endif | |
7109 | 1473 elseif (nd == 3) |
6510 | 1474 ## FIXME -- handle NaNs here too? |
1475 if (parametric) | |
6914 | 1476 fprintf (plot_stream, "%.15g %.15g %.15g\n", data); |
6510 | 1477 else |
7170 | 1478 nr = rows (data); |
7119 | 1479 if (cdata) |
7170 | 1480 for j = 1:4:nr |
1481 fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data(j:j+3,:)); | |
7119 | 1482 fputs (plot_stream, "\n"); |
1483 endfor | |
1484 else | |
7170 | 1485 for j = 1:3:nr |
1486 fprintf (plot_stream, "%.15g %.15g %.15g\n", data(j:j+2,:)); | |
7119 | 1487 fputs (plot_stream, "\n"); |
1488 endfor | |
1489 endif | |
7109 | 1490 endif |
6510 | 1491 endif |
1492 fputs (plot_stream, "e\n"); | |
1493 | |
1494 endfunction | |
6745 | 1495 |
7269 | 1496 function do_tics (obj, plot_stream, ymirror, mono) |
6809 | 1497 if (strcmpi (obj.xaxislocation, "top")) |
1498 do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, | |
7321 | 1499 obj.xcolor, "x2", plot_stream, true, mono, "border"); |
6809 | 1500 do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, |
7321 | 1501 obj.xcolor, "x", plot_stream, true, mono, "border"); |
1502 elseif (strcmpi (obj.xaxislocation, "zero")) | |
1503 do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, | |
1504 obj.xcolor, "x", plot_stream, true, mono, "axis"); | |
1505 do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, | |
1506 obj.xcolor, "x2", plot_stream, true, mono, "axis"); | |
6809 | 1507 else |
1508 do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, | |
7321 | 1509 obj.xcolor, "x", plot_stream, true, mono, "border"); |
6809 | 1510 do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, |
7321 | 1511 obj.xcolor, "x2", plot_stream, true, mono, "border"); |
6809 | 1512 endif |
1513 if (strcmpi (obj.yaxislocation, "right")) | |
1514 do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, | |
7321 | 1515 obj.ycolor, "y2", plot_stream, ymirror, mono, "border"); |
6809 | 1516 do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, |
7321 | 1517 obj.ycolor, "y", plot_stream, ymirror, mono, "border"); |
1518 elseif (strcmpi (obj.xaxislocation, "zero")) | |
1519 do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, | |
1520 obj.ycolor, "y", plot_stream, ymirror, mono, "axis"); | |
1521 do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, | |
1522 obj.ycolor, "y2", plot_stream, ymirror, mono, "axis"); | |
6809 | 1523 else |
1524 do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, | |
7321 | 1525 obj.ycolor, "y", plot_stream, ymirror, mono, "border"); |
6809 | 1526 do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, |
7321 | 1527 obj.ycolor, "y2", plot_stream, ymirror, mono, "border"); |
6809 | 1528 endif |
6745 | 1529 do_tics_1 (obj.ztickmode, obj.ztick, obj.zticklabelmode, obj.zticklabel, |
7321 | 1530 obj.zcolor, "z", plot_stream, true, mono, "border"); |
6745 | 1531 endfunction |
1532 | |
7269 | 1533 function do_tics_1 (ticmode, tics, labelmode, labels, color, ax, |
7321 | 1534 plot_stream, mirror, mono, axispos) |
7269 | 1535 colorspec = get_text_colorspec (color, mono); |
6758 | 1536 if (strcmpi (ticmode, "manual")) |
6745 | 1537 if (isempty (tics)) |
1538 fprintf (plot_stream, "unset %stics;\n", ax); | |
6758 | 1539 elseif (strcmpi (labelmode, "manual") && ! isempty (labels)) |
6751 | 1540 if (ischar (labels)) |
1541 labels = cellstr (labels); | |
1542 endif | |
6745 | 1543 if (iscellstr (labels)) |
6751 | 1544 k = 1; |
1545 ntics = numel (tics); | |
1546 nlabels = numel (labels); | |
6745 | 1547 fprintf (plot_stream, "set format %s \"%%s\";\n", ax); |
7206 | 1548 if (mirror) |
7321 | 1549 fprintf (plot_stream, "set %stics %s (", ax, axispos); |
7206 | 1550 else |
7321 | 1551 fprintf (plot_stream, "set %stics %s nomirror (", ax, axispos); |
7206 | 1552 endif |
7228 | 1553 labels = regexprep(labels, "%", "%%"); |
6745 | 1554 for i = 1:ntics |
7228 | 1555 fprintf (plot_stream, " \"%s\" %g", labels{k++}, tics(i)) |
6745 | 1556 if (i < ntics) |
1557 fputs (plot_stream, ", "); | |
1558 endif | |
1559 if (k > nlabels) | |
1560 k = 1; | |
1561 endif | |
1562 endfor | |
7220 | 1563 fprintf (plot_stream, ") %s;\n", colorspec); |
6745 | 1564 else |
1565 error ("unsupported type of ticklabel"); | |
1566 endif | |
1567 else | |
6920 | 1568 fprintf (plot_stream, "set format %s \"%%g\";\n", ax); |
7206 | 1569 if (mirror) |
7321 | 1570 fprintf (plot_stream, "set %stics %s (", ax, axispos ); |
7206 | 1571 else |
7321 | 1572 fprintf (plot_stream, "set %stics %s nomirror (", ax, axispos); |
7206 | 1573 endif |
6920 | 1574 fprintf (plot_stream, " %g,", tics(1:end-1)); |
1575 fprintf (plot_stream, " %g);\n", tics(end)); | |
6745 | 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 %s;\n", ax, axispos, colorspec); |
7206 | 1581 else |
7321 | 1582 fprintf (plot_stream, "set %stics %s nomirror %s;\n", ax, |
1583 axispos, colorspec); | |
7206 | 1584 endif |
7194 | 1585 endif |
1586 endfunction | |
1587 | |
7269 | 1588 function colorspec = get_text_colorspec (color, mono) |
7194 | 1589 persistent have_newer_gnuplot ... |
1590 = compare_versions (__gnuplot_version__ (), "4.0", ">"); | |
1591 | |
1592 if (have_newer_gnuplot) | |
7269 | 1593 if (mono) |
1594 colorspec = ""; | |
1595 else | |
1596 colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"", | |
1597 round (255*color)); | |
1598 endif | |
7194 | 1599 else |
1600 if (isequal (color, [0,0,0])) | |
1601 typ = -1; | |
1602 elseif (isequal (color, [1,0,0])) | |
1603 typ = 1; | |
1604 elseif (isequal (color, [0,1,0])) | |
1605 typ = 2; | |
1606 elseif (isequal (color, [0,0,1])) | |
1607 typ = 3; | |
1608 elseif (isequal (color, [1,0,1])) | |
1609 typ = 4; | |
1610 elseif (isequal (color, [0,1,1])) | |
1611 typ = 5; | |
1612 elseif (isequal (color, [1,1,1])) | |
1613 typ = -1; | |
1614 elseif (isequal (color, [1,1,0])) | |
1615 typ = 7; | |
1616 else | |
1617 typ = -1; | |
1618 endif | |
1619 colorspec = sprintf ("textcolor lt %d", typ); | |
6745 | 1620 endif |
1621 endfunction | |
7163 | 1622 |
7189 | 1623 function [f, s, fnt, it, bld] = get_fontname_and_size (t) |
7163 | 1624 if (isempty (t.fontname)) |
7189 | 1625 fnt = "helvetica"; |
7163 | 1626 else |
7189 | 1627 fnt = tolower (t.fontname); |
7168 | 1628 endif |
7189 | 1629 f = fnt; |
1630 it = false; | |
1631 bld = false; | |
7168 | 1632 if (! isempty (t.fontweight) && strcmp (tolower (t.fontweight), "bold")) |
1633 if (! isempty(t.fontangle) | |
1634 && (strcmp (tolower (t.fontangle), "italic") | |
1635 || strcmp (tolower (t.fontangle), "oblique"))) | |
1636 f = strcat (f, "-bolditalic"); | |
7189 | 1637 it = true; |
1638 bld = true; | |
7168 | 1639 else |
1640 f = strcat (f, "-bold"); | |
7189 | 1641 bld = true; |
7168 | 1642 endif |
1643 elseif (! isempty(t.fontangle) | |
1644 && (strcmp (tolower (t.fontangle), "italic") | |
1645 || strcmp (tolower (t.fontangle), "oblique"))) | |
1646 f = strcat (f, "-italic"); | |
7189 | 1647 it = true; |
7163 | 1648 endif |
1649 if (isempty (t.fontsize)) | |
1650 s = 10; | |
1651 else | |
1652 s = t.fontsize; | |
1653 endif | |
1654 endfunction | |
7189 | 1655 |
1656 function [str, f, s] = __maybe_munge_text__ (enhanced, obj, fld, | |
1657 have_newer_gnuplot) | |
1658 persistent warned_latex = false; | |
1659 | |
1660 if (strcmp (fld, "string")) | |
1661 [f, s, fnt, it, bld] = get_fontname_and_size (obj); | |
1662 else | |
1663 f = "Helvectica"; | |
1664 s = 10; | |
1665 fnt = f; | |
1666 it = false; | |
1667 bld = false; | |
1668 endif | |
1669 | |
1670 str = getfield (obj, fld); | |
1671 if (enhanced) | |
1672 if (strcmp (obj.interpreter, "tex")) | |
1673 str = __tex2enhanced__ (str, fnt, it, bld); | |
1674 if (! have_newer_gnuplot) | |
1675 ## Set the font to work around gnuplot 4.0 X11 enhanced terminal bug | |
1676 str = strcat ('{/', f, ' ', str, ' }'); | |
1677 endif | |
1678 elseif (strcmp (obj.interpreter, "latex")) | |
1679 if (! warned_latex) | |
1680 warning ("latex text objects not supported"); | |
1681 warned_latex = true; | |
1682 endif | |
1683 endif | |
1684 endif | |
1685 endfunction | |
1686 | |
1687 function str = __tex2enhanced__ (str, fnt, it, bld) | |
1688 persistent sym = __setup_sym_table__ (); | |
1689 persistent flds = fieldnames (sym); | |
1690 | |
1691 [s, e, m] = regexp(str,'\\([a-zA-Z]+|0)','start','end','matches'); | |
1692 | |
1693 for i = length (s) : -1 : 1 | |
1694 ## special case for "\0" and replace with "{/Symbol \306}' | |
1695 if (strncmp (m{i}, '\0', 2)) | |
7190 | 1696 str = strcat (str(1:s(i) - 1), '{/Symbol \306}', str(s(i) + 2:end)); |
7189 | 1697 else |
1698 f = m{i}(2:end); | |
1699 if (isfield (sym, f)) | |
1700 g = getfield(sym, f); | |
1701 ## FIXME The symbol font doesn't seem to support bold or italic | |
1702 ##if (bld) | |
1703 ## if (it) | |
1704 ## g = regexprep (g, '/Symbol', '/Symbol-bolditalic'); | |
1705 ## else | |
1706 ## g = regexprep (g, '/Symbol', '/Symbol-bold'); | |
1707 ## endif | |
1708 ##elseif (it) | |
1709 ## g = regexprep (g, '/Symbol', '/Symbol-italic'); | |
1710 ##endif | |
1711 str = strcat (str(1:s(i) - 1), g, str(e(i) + 1:end)); | |
1712 elseif (strncmp (f, "rm", 2)) | |
1713 bld = false; | |
1714 it = false; | |
1715 str = strcat (str(1:s(i) - 1), '/', fnt, ' ', str(s(i) + 3:end)); | |
1716 elseif (strncmp (f, "it", 2) || strncmp (f, "sl", 2)) | |
1717 it = true; | |
1718 if (bld) | |
1719 str = strcat (str(1:s(i) - 1), '/', fnt, '-bolditalic ', | |
1720 str(s(i) + 3:end)); | |
1721 else | |
1722 str = strcat (str(1:s(i) - 1), '/', fnt, '-italic ', | |
1723 str(s(i) + 3:end)); | |
1724 endif | |
1725 elseif (strncmp (f, "bf", 2)) | |
1726 bld = true; | |
1727 if (it) | |
1728 str = strcat (str(1:s(i) - 1), '/', fnt, '-bolditalic ', | |
1729 str(2(i) + 3:end)); | |
1730 else | |
1731 str = strcat (str(1:s(i) - 1), '/', fnt, '-bold ', | |
1732 str(s(i) + 3:end)); | |
1733 endif | |
1734 elseif (strcmp (f, "color")) | |
1735 ## FIXME Ignore \color but remove trailing {} block as well | |
1736 d = strfind(str(e(i) + 1:end),'}'); | |
1737 if (isempty (d)) | |
1738 warning ('syntax error in \color argument'); | |
1739 else | |
1740 str = strcat (str(1:s(i) - 1), str(e(i) + d + 1:end)); | |
1741 endif | |
1742 elseif(strcmp (f, "fontname")) | |
1743 b1 = strfind(str(e(i) + 1:end),'{'); | |
1744 b2 = strfind(str(e(i) + 1:end),'}'); | |
1745 if (isempty(b1) || isempty(b2)) | |
1746 warning ('syntax error in \fontname argument'); | |
1747 else | |
1748 str = strcat (str(1:s(i) - 1), '/', | |
1749 str(e(i)+b1(1) + 1:e(i)+b2(1)-1), '{}', | |
1750 str(e(i) + b2(1) + 1:end)); | |
1751 endif | |
1752 elseif(strcmp (f, "fontsize")) | |
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 else | |
1763 ## Last desperate attempt to treat the symbol. Look for things | |
1764 ## like \pix, that should be translated to the symbol Pi and x | |
1765 for j = 1 : length (flds) | |
1766 if (strncmp (flds{j}, f, length (flds{j}))) | |
1767 g = getfield(sym, flds{j}); | |
1768 ## FIXME The symbol font doesn't seem to support bold or italic | |
1769 ##if (bld) | |
1770 ## if (it) | |
1771 ## g = regexprep (g, '/Symbol', '/Symbol-bolditalic'); | |
1772 ## else | |
1773 ## g = regexprep (g, '/Symbol', '/Symbol-bold'); | |
1774 ## endif | |
1775 ##elseif (it) | |
1776 ## g = regexprep (g, '/Symbol', '/Symbol-italic'); | |
1777 ##endif | |
1778 str = strcat (str(1:s(i) - 1), g, | |
1779 str(s(i) + length (flds{j}) + 1:end)); | |
1780 break; | |
1781 endif | |
1782 endfor | |
1783 endif | |
1784 endif | |
1785 endfor | |
1786 | |
1787 ## Prepend @ to things things like _0^x or _{-100}^{100} for alignment | |
1788 ## But need to put the shorter of the two arguments first. Carful of | |
1789 ## nested {} and unprinted characters when defining shortest.. Don't | |
1790 ## have to worry about things like ^\theta as they are already converted to | |
1791 ## ^{/Symbol q}. | |
1792 | |
1793 ## FIXME.. This is a mess... Is it worth it just for a "@" character? | |
1794 | |
1795 [s, m] = regexp(str,'[_\^]','start','matches'); | |
1796 i = 1; | |
1797 p = 0; | |
1798 while (i < length (s)) | |
1799 if (i < length(s)) | |
1800 if (str(s(i) + p + 1) == "{") | |
1801 s1 = strfind(str(s(i) + p + 2:end),'{'); | |
1802 si = 1; | |
1803 l1 = strfind(str(s(i) + p + 1:end),'}'); | |
1804 li = 1; | |
1805 while (li <= length (l1) && si <= length (s1)) | |
1806 if (l1(li) < s1(si)) | |
1807 if (li == si) | |
1808 break; | |
1809 endif | |
1810 li++; | |
1811 else | |
1812 si++; | |
1813 endif | |
1814 endwhile | |
1815 l1 = l1 (min (length(l1), si)); | |
1816 if (s(i) + l1 + 1 == s(i+1)) | |
1817 if (str(s(i + 1) + p + 1) == "{") | |
1818 s2 = strfind(str(s(i + 1) + p + 2:end),'{'); | |
1819 si = 1; | |
1820 l2 = strfind(str(s(i + 1) + p + 1:end),'}'); | |
1821 li = 1; | |
1822 while (li <= length (l2) && si <= length (s2)) | |
1823 if (l2(li) < s2(si)) | |
1824 if (li == si) | |
1825 break; | |
1826 endif | |
1827 li++; | |
1828 else | |
1829 si++; | |
1830 endif | |
1831 endwhile | |
1832 l2 = l2 (min (length(l2), si)); | |
1833 if (length_string (str(s(i)+p+2:s(i)+p+l1-1)) <= | |
1834 length_string(str(s(i+1)+p+2:s(i+1)+p+l2-1))) | |
1835 ## shortest already first! | |
1836 str = strcat (str(1:s(i)+p-1), "@", str(s(i)+p:end)); | |
1837 else | |
1838 ## Have to swap sub/super-script to get shortest first | |
1839 str = strcat (str(1:s(i)+p-1), "@", str(s(i+1)+p:s(i+1)+p+l2), | |
1840 str(s(i)+p:s(i)+p+l1), str(s(i+1)+p+l2+1:end)); | |
1841 endif | |
1842 else | |
1843 ## Have to swap sub/super-script to get shortest first | |
1844 str = strcat (str(1:s(i)+p-1), "@", str(s(i+1)+p:s(i+1)+p+1), | |
1845 str(s(i)+p:s(i)+p+l1), str(s(i+1)+p+2:end)); | |
1846 endif | |
1847 i += 2; | |
1848 p ++; | |
1849 else | |
1850 i++; | |
1851 endif | |
1852 else | |
1853 if (s(i+1) == s(i) + 2) | |
1854 ## shortest already first! | |
1855 str = strcat (str(1:s(i)+p-1), "@", str(s(i)+p:end)); | |
1856 p ++; | |
1857 i += 2; | |
1858 else | |
1859 i ++; | |
1860 endif | |
1861 endif | |
1862 else | |
1863 i ++; | |
1864 endif | |
1865 endwhile | |
1866 | |
1867 endfunction | |
1868 | |
1869 function l = length_string (s) | |
1870 l = length (s) - length (strfind(s,'{')) - length (strfind(s,'}')); | |
1871 m = regexp (s, '/([\w\-]+|[\w\-]+=\d+)', 'matches'); | |
1872 if (!isempty (m)) | |
1873 l = l - sum (cellfun (@length, m)); | |
1874 endif | |
1875 endfunction | |
1876 | |
1877 function sym = __setup_sym_table__ () | |
1878 ## Setup the translation table for TeX to gnuplot enhanced mode. | |
1879 sym.forall = '{/Symbol \042}'; | |
1880 sym.exists = '{/Symbol \044}'; | |
1881 sym.ni = '{/Symbol \047}'; | |
1882 sym.cong = '{/Symbol \100}'; | |
1883 sym.Delta = '{/Symbol D}'; | |
1884 sym.Phi = '{/Symbol F}'; | |
1885 sym.Gamma = '/Symbol G}'; | |
7190 | 1886 sym.vartheta = '{/Symbol J}'; |
7189 | 1887 sym.Lambda = '{/Symbol L}'; |
1888 sym.Pi = '{/Symbol P}'; | |
1889 sym.Theta = '{/Symbol Q}'; | |
1890 sym.Sigma = '{/Symbol S}'; | |
1891 sym.varsigma = '{/Symbol V}'; | |
11622 | 1892 sym.Omega = '{/Symbol W}'; |
7189 | 1893 sym.Xi = '{/Symbol X}'; |
1894 sym.Psi = '{/Symbol Y}'; | |
1895 sym.perp = '{/Symbol \136}'; | |
1896 sym.alpha = '{/Symbol a}'; | |
1897 sym.beta = '{/Symbol b}'; | |
1898 sym.chi = '{/Symbol c}'; | |
1899 sym.delta = '{/Symbol d}'; | |
1900 sym.epsilon = '{/Symbol e}'; | |
1901 sym.phi = '{/Symbol f}'; | |
1902 sym.gamma = '/Symbol g}'; | |
1903 sym.eta = '{/Symbol h}'; | |
1904 sym.iota = '{/Symbol i}'; | |
1905 sym.kappa = '{/Symbol k}'; | |
1906 sym.lambda = '{/Symbol l}'; | |
1907 sym.mu = '{/Symbol m}'; | |
1908 sym.nu = '{/Symbol n}'; | |
1909 sym.o = '{/Symbol o}'; | |
1910 sym.pi = '{/Symbol p}'; | |
1911 sym.theta = '{/Symbol q}'; | |
1912 sym.rho = '{/Symbol r}'; | |
1913 sym.sigma = '{/Symbol s}'; | |
1914 sym.tau = '{/Symbol t}'; | |
1915 sym.upsilon = '{/Symbol u}'; | |
1916 sym.varpi = '{/Symbol v}'; | |
1917 sym.omega = '{/Symbol w}'; | |
1918 sym.xi = '{/Symbol x}'; | |
1919 sym.psi = '{/Symbol y}'; | |
1920 sym.zeta = '{/Symbol z}'; | |
1921 sym.sim = '{/Symbol \176}'; | |
1922 sym.Upsilon = '{/Symbol \241}'; | |
1923 sym.prime = '{/Symbol \242}'; | |
1924 sym.leq = '{/Symbol \243}'; | |
1925 sym.infty = '{/Symbol \245}'; | |
1926 sym.clubsuit = '{/Symbol \247}'; | |
1927 sym.diamondsuit = '{/Symbol \250}'; | |
1928 sym.heartsuit = '{/Symbol \251}'; | |
1929 sym.spadesuit = '{/Symbol \252}'; | |
1930 sym.leftrightarrow = '{/Symbol \253}'; | |
1931 sym.leftarrow = '{/Symbol \254}'; | |
1932 sym.uparrow = '{/Symbol \255}'; | |
1933 sym.rightarrow = '{/Symbol \256}'; | |
1934 sym.downarrow = '{/Symbol \257}'; | |
1935 sym.circ = '{/Symbol \260}'; | |
1936 sym.pm = '{/Symbol \261}'; | |
1937 sym.geq = '{/Symbol \263}'; | |
1938 sym.times = '{/Symbol \264}'; | |
1939 sym.propto = '{/Symbol \265}'; | |
1940 sym.partial = '{/Symbol \266}'; | |
1941 sym.bullet = '{/Symbol \267}'; | |
1942 sym.div = '{/Symbol \270}'; | |
1943 sym.neq = '{/Symbol \271}'; | |
1944 sym.equiv = '{/Symbol \272}'; | |
1945 sym.approx = '{/Symbol \273}'; | |
1946 sym.ldots = '{/Symbol \274}'; | |
1947 sym.mid = '{/Symbol \275}'; | |
1948 sym.aleph = '{/Symbol \300}'; | |
1949 sym.Im = '{/Symbol \301}'; | |
1950 sym.Re = '{/Symbol \302}'; | |
1951 sym.wp = '{/Symbol \303}'; | |
1952 sym.otimes = '{/Symbol \304}'; | |
1953 sym.oplus = '{/Symbol \305}'; | |
1954 sym.oslash = '{/Symbol \306}'; | |
1955 sym.cap = '{/Symbol \307}'; | |
1956 sym.cup = '{/Symbol \310}'; | |
1957 sym.supset = '{/Symbol \311}'; | |
1958 sym.supseteq = '{/Symbol \312}'; | |
1959 sym.subset = '{/Symbol \314}'; | |
1960 sym.subseteq = '{/Symbol \315}'; | |
1961 sym.in = '{/Symbol \316}'; | |
1962 sym.langle = '{/Symbol \320}'; | |
1963 sym.rangle = '{/Symbol \320}'; | |
1964 sym.nabla = '{/Symbol \321}'; | |
1965 sym.surd = '{/Symbol \326}'; | |
1966 sym.cdot = '{/Symbol \327}'; | |
1967 sym.neg = '{/Symbol \330}'; | |
1968 sym.wedge = '{/Symbol \331}'; | |
1969 sym.vee = '{/Symbol \332}'; | |
1970 sym.copyright = '{/Symbol \343}'; | |
1971 sym.rfloor = '{/Symbol \353}'; | |
1972 sym.lceil = '{/Symbol \351}'; | |
1973 sym.lfloor = '{/Symbol \373}'; | |
1974 sym.rceil = '{/Symbol \371}'; | |
1975 sym.int = '{/Symbol \362}'; | |
1976 endfunction | |
1977 | |
1978 function [pos, orient, sz, origin, mirr] = gnuplot_postion_colorbox (pos, cbox) | |
1979 ## This is an emprically derived function that | |
1980 | |
1981 if (strncmp (cbox, "north", 5) || strncmp (cbox, "south", 5)) | |
1982 scl = pos([2,4]); | |
1983 else | |
1984 scl = pos([1,3]); | |
1985 endif | |
1986 | |
1987 if (length(cbox) > 7 && strncmp (cbox(end-6:end), "outside", 7)) | |
1988 scl(2) -= 0.2 * scl(2); | |
1989 if (strncmp (cbox, "west", 4) || strncmp (cbox, "south", 5)) | |
1990 scl(1) += 0.2 * scl(2); | |
1991 endif | |
1992 endif | |
1993 | |
1994 switch (cbox) | |
1995 case "northoutside" | |
1996 sz = pos(3:4) - 0.08; | |
1997 origin = [0.05, 0.06] + [0.00, 0.88] .* sz + pos(1:2); | |
1998 mirr = true; | |
1999 orient = "horizontal"; | |
2000 case "north" | |
2001 sz = pos(3:4) - 0.16; | |
2002 origin = [0.09, 0.09] + [0.00, 0.94] .* sz + pos(1:2); | |
2003 mirr = false; | |
2004 orient = "horizontal"; | |
2005 case "southoutside" | |
2006 sz = pos(3:4) - 0.08; | |
2007 origin = [0.05, 0.06] + [0.00, 0.00] .* sz + pos(1:2); | |
2008 mirr = false; | |
2009 orient = "horizontal"; | |
2010 case "south" | |
2011 sz = pos(3:4) - 0.16; | |
2012 origin = [0.08, 0.09] + [0.03, 0.05] .* sz + pos(1:2); | |
2013 mirr = true; | |
2014 orient = "horizontal"; | |
2015 case "eastoutside" | |
2016 sz = pos(3:4) - 0.08; | |
2017 origin = [0.00, 0.06] + [0.94, 0.00] .* sz + pos(1:2); | |
2018 mirr = false; | |
2019 orient = "vertical"; | |
2020 case "east" | |
2021 sz = pos(3:4) - 0.16; | |
2022 origin = [0.09, 0.10] + [0.91, 0.01] .* sz + pos(1:2); | |
2023 mirr = true; | |
2024 orient = "vertical"; | |
2025 case "westoutside" | |
2026 sz = pos(3:4) - 0.08; | |
2027 origin = [0.00, 0.06] + [0.06, 0.00] .* sz + pos(1:2); | |
2028 mirr = true; | |
2029 orient = "vertical"; | |
2030 case "west" | |
2031 sz = pos(3:4) - 0.16; | |
2032 origin = [0.06, 0.09] + [0.04, 0.03] .* sz + pos(1:2); | |
2033 mirr = false; | |
2034 orient = "vertical"; | |
2035 endswitch | |
2036 | |
2037 if (strncmp (cbox, "north", 5) || strncmp (cbox, "south", 5)) | |
2038 sz = sz .* [1, 0.07]; | |
2039 pos([2,4]) = scl; | |
2040 else | |
2041 sz = sz .* [0.07, 1]; | |
2042 pos([1,3]) = scl; | |
2043 endif | |
2044 | |
2045 endfunction | |
11615 | 2046 |
2047 function retval = __do_enhanced_option__ (enhanced, obj) | |
2048 retval = ""; | |
2049 if (enhanced) | |
2050 if (strcmpi (obj.interpreter, "none")) | |
2051 retval = "noenhanced"; | |
2052 else | |
2053 retval = "enhanced"; | |
2054 endif | |
2055 endif | |
2056 endfunction |