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