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