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