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