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