Mercurial > hg > octave-lyh
changeset 6172:2de853a110df
[project @ 2006-11-15 22:53:47 by jwe]
author | jwe |
---|---|
date | Wed, 15 Nov 2006 22:53:48 +0000 |
parents | 4508e9d73ea1 |
children | dae08571782e |
files | scripts/ChangeLog scripts/image/__img_gnuplot__.m scripts/plot/__errplot__.m scripts/plot/__init_plot_vars__.m scripts/plot/__plot_globals__.m scripts/plot/__plt3__.m scripts/plot/__plt__.m scripts/plot/__render_plot__.m scripts/plot/__setup_plot__.m scripts/plot/contour.m scripts/plot/mesh.m scripts/plot/plot3.m scripts/plot/replot.m |
diffstat | 13 files changed, 344 insertions(+), 220 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,30 @@ +2006-11-15 John W. Eaton <jwe@octave.org> + + * image/__img_gnuplot__.m: Store more info in global plot + structures and use __render_plot__ to build plot command to + display image. + + * plot/__plt3__.m: New arg, parametric. Change all callers. + + * plot/__plot_globals__.m (__plot_line_offset__, __plot_command__, + __plot_command_sep__): Delete. + (__plot_data_type__, __plot_data_parametric__, + __plot_image_colormap__, __plot_image_dims__, __plot_fmtstr__, + __plot_usingstr__, __plot_withstr__): New variables. + * plot/__init_plot_vars__.m: Initialize them. + + * plot/__init_plot_vars__.m, plot/__setup_plot__.m: + Don't handle sep or cmd. + + * plot/__render_plot__.m: New function. + * plot/__plt__.m, plot/__plt3__.m, plot/__errplot__.m: + Store more info in global plot structures and use __render_plot__ + to build plot command. + * plot/replot.m: Simply call __render_plot__. + + * plot/contour.m, plot/mesh.m, plot/plot3.m: + Set __plot_data_parametric__ here. + 2006-11-14 John W. Eaton <jwe@octave.org> * plot/bottom_title.m, plot/top_title.m: Delete.
--- a/scripts/image/__img_gnuplot__.m +++ b/scripts/image/__img_gnuplot__.m @@ -26,84 +26,71 @@ ## ZOOM is ignored. + __plot_globals__; + + cf = __current_figure__; + mxi = __multiplot_xi__(cf); + myi = __multiplot_yi__(cf); + + __setup_plot__ ("plot"); + if (nargin < 3) print_usage (); endif if (isempty (A)) - error ("image matrix is empty"); - endif - - __gnuplot_raw__ ("set nokey\n"); - __gnuplot_raw__ ("set size ratio -1;\n"); - __current_color_map__ = colormap (); - palette_size = size (__current_color_map__, 1); - __gnuplot_raw__ (sprintf ("set palette positive color model RGB maxcolors %i\n", palette_size)); - if (palette_size <= 128) - ## Break up command to avoid buffer overflow. - __gnuplot_raw__ ("set palette file \"-\"\n"); - for i = 1:palette_size - __gnuplot_raw__ (sprintf ("%g %g %g %g\n", 1e-3 * round (1e3 * [(i-1)/(palette_size-1), __current_color_map__(i,:)]))); - end - __gnuplot_raw__("e\n"); - else - ## Let the file be deleted when Octave exits or `purge_tmp_files' is called. - [fid, binary_file_name, msg] = mkstemp ([P_tmpdir,"/gpimageXXXXXX"], 1); - fwrite (fid, __current_color_map__', "float32", 0, "ieee-le"); - fclose (fid); - __gnuplot_raw__ (sprintf ("set palette file \"%s\" binary record=%d using 1:2:3\n", binary_file_name, palette_size)); + error ("__img_gnuplot__: matrix is empty"); endif ## Use the newly added mode of "plot" called "with image". if (isempty (x)) - x = [1, size(A,2)]; - y = [1, size(A,1)]; + x = [1, columns(A)]; + y = [1, rows(A)]; endif ## Force rectangular grid by using only end points of ## first row (column) if x (y) is a matrix or vector. - if ((size (x, 2)) > 1) + if (columns (x) > 1) x = x(1,:)'; endif - if (abs (x(end) - x(1)) < (10*eps)) - error ("end points in x dimension must not be equal"); + if (abs (x(end) - x(1)) < 10*eps) + error ("__img_gnuplot__: end points in x dimension must not be equal"); else x_dim = size (A, 2); if (x_dim > 1) - dx = (x(end)-x(1))/(x_dim-1); + dx = abs (x(end)-x(1))/(x_dim-1); else dx = 1; endif endif - if ((size (y, 1)) > 1) + if (rows (y) > 1) y = y(:,1)'; endif - if (abs(y(end) - y(1)) < 10*eps) - error ("end points in y dimension must not be equal"); + if (abs (y(end) - y(1)) < 10*eps) + error ("__img_gnuplot__: end points in y dimension must not be equal"); else y_dim = size (A, 1); if (y_dim > 1) - dy = (y(end)-y(1))/(y_dim-1); + dy = abs (y(end)-y(1))/(y_dim-1); else dy = 1; endif endif - __gnuplot_raw__ (sprintf ("set xrange [%g:%g]\n", x(1)-dx/2, x(end)+dx/2)); - __gnuplot_raw__ (sprintf ("set yrange [%g:%g]\n", y(1)-dy/2, y(end)+dy/2)); - __gnuplot_raw__ ("set autoscale fix\n"); # "fix" is helpful for "a" hotkey - __gnuplot_raw__ ("set tics out\n"); + x_origin = min (x(1), x(end)); + y_origin = min (y(1), y(end)); + + j = __plot_data_offset__{cf}(mxi,myi); - A = reshape(A,size(A,1)*size(A,2),1); - ## Let the file be deleted when Octave exits or `purge_tmp_files' is called. - [fid, binary_file_name, msg] = mkstemp ([P_tmpdir, "/gpimageXXXXXX"], 1); - ## Gnuplot reads binary files very quickly. However, the 'fwrite' below - ## is much slower than using the current '__gnuplot_plot__' command. - fwrite (fid, A', "float", 0, "ieee-le"); - fclose (fid); - __gnuplot_raw__ (sprintf ("plot \"%s\" binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g endian=little using 1 with image\n", binary_file_name, x_dim, y_dim, min (x(1), x(end)), min(y(1), y(end)), abs (dx), abs (dy))); - ## Put back in default data mode. - __gnuplot_raw__ ("set xrange [*:*];\n"); - __gnuplot_raw__ ("set yrange [*:*];\n"); + __plot_data__{cf}{mxi,myi}{j}{1} = A; + __plot_data_type__{cf}{mxi,myi}(j) = 1; + __plot_key_labels__{cf}{mxi,myi}{j}{1} = ""; + __plot_image_colormap__{cf}{mxi,myi} = colormap (); + __plot_image_dims__{cf}{mxi,myi}{j}{1} ... + = [x_dim, y_dim, x_origin, y_origin, dx, dy]; + + __plot_data_offset__{cf}(mxi,myi) = ++j; + + __render_plot__ (); endfunction
--- a/scripts/plot/__errplot__.m +++ b/scripts/plot/__errplot__.m @@ -49,21 +49,12 @@ j = __plot_data_offset__{cf}(mxi,myi); - loff = __plot_line_offset__{cf}(mxi,myi); - [fmt, key] = __pltopt__ ("__errplot__", fstr); - nkey = numel (key); + [len, nplots] = size (a1); - nplots = size (a1, 2); - len = size (a1, 1); for i = 1:nplots - ifmt = fmt{1+mod(i-1,numel(fmt))}; - if (i <= nkey) - __plot_key_labels__{cf}{mxi,myi}{loff} = key{i}; - else - __plot_key_labels__{cf}{mxi,myi}{loff} = ""; - endif + ifmt = fmt{1+mod(i-1,numel(fmt))} switch (nargin - 1) case 2 tmp = [(1:len)', a1(:,i), a2(:,i)]; @@ -86,29 +77,17 @@ a2(:,i)-a5(:,i), a2(:,i)+a6(:,i)]; endswitch - __plot_data__{cf}{mxi,myi}{j} = tmp; - - __plot_command__{cf}{mxi,myi} \ - = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)}{%d} %s %s __plot_key_labels__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)}{%d}", - __plot_command__{cf}{mxi,myi}, - __plot_command_sep__, j, ifmt, - gnuplot_command_title, loff); - __plot_command_sep__ = ",\\\n"; - - j++; - loff++; + __plot_data__{cf}{mxi,myi}{j}{i} = tmp; + __plot_data_type__{cf}{mxi,myi}(j) = 2; + __plot_fmtstr__{cf}{mxi,myi}{j}{i} = ifmt; + __plot_key_labels__{cf}{mxi,myi}{j} = key; + __plot_usingstr__{cf}{mxi,myi}{j}{i} = ""; + __plot_withstr__{cf}{mxi,myi}{j}{i} = ""; endfor - __plot_data_offset__{cf}(mxi,myi) = j; - __plot_line_offset__{cf}(mxi,myi) = loff; + __plot_data_offset__{cf}(mxi,myi) = ++j; - if (! isempty (__plot_command__{cf}{mxi,myi})) - if (__multiplot_mode__(cf)) - __gnuplot_raw__ ("clear\n"); - endif - __do_legend__ (); - eval (__plot_command__{cf}{mxi,myi}); - endif + __render_plot__ (); endfunction
--- a/scripts/plot/__init_plot_vars__.m +++ b/scripts/plot/__init_plot_vars__.m @@ -17,7 +17,7 @@ ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. -function __init_plot_vars__ (cmd, sep, clear_data) +function __init_plot_vars__ (clear_data) __plot_globals__; @@ -25,24 +25,20 @@ mxi = __multiplot_xi__(cf); myi = __multiplot_yi__(cf); - if (nargin < 3) + if (nargin < 1) clear_data = true; - if (nargin < 2) - sep = ""; - if (nargin < 1) - cmd = ""; - endif - endif endif - __plot_command__{cf}{mxi,myi} = cmd; - __plot_command_sep__ = sep; - if (clear_data) __plot_data__{cf}{mxi,myi} = []; __plot_data_offset__{cf}(mxi,myi) = 1; - __plot_line_offset__{cf}(mxi,myi) = 1; - __plot_key_labels__{cf}{mxi,myi} = []; + __plot_data_type__{cf}{mxi,myi} = []; + __plot_data_parametric__{cf}{mxi,myi} = []; + __plot_image_colormap__{cf}{mxi,myi} = []; + __plot_image_dims__{cf}{mxi,myi} = []; + __plot_fmtstr__{cf}{mxi,myi} = []; + __plot_usingstr__{cf}{mxi,myi} = []; + __plot_withstr__{cf}{mxi,myi} = []; endif endfunction
--- a/scripts/plot/__plot_globals__.m +++ b/scripts/plot/__plot_globals__.m @@ -19,10 +19,14 @@ global __current_figure__; global __plot_data_offset__; -global __plot_line_offset__; -global __plot_command__; -global __plot_command_sep__; global __plot_data__; +global __plot_data_type__; +global __plot_data_parametric__; +global __plot_image_colormap__; +global __plot_image_dims__; +global __plot_fmtstr__; +global __plot_usingstr__; +global __plot_withstr__; global __plot_key_labels__; global __plot_key_properties__; global __multiplot_mode__; @@ -71,22 +75,46 @@ __plot_data_offset__{__current_figure__}(__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)) = 1; endif -if (length (__plot_line_offset__) < __current_figure__ - || any (size (__plot_line_offset__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) - - __plot_line_offset__{__current_figure__}(__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)) = 1; -endif - -if (length (__plot_command__) < __current_figure__ - || any (size (__plot_command__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) - __plot_command__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = ""; -endif - if (length (__plot_data__) < __current_figure__ || any (size (__plot_data__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) __plot_data__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = []; endif +if (length (__plot_data_type__) < __current_figure__ + || any (size (__plot_data_type__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) + __plot_data_type__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = []; +endif + +if (length (__plot_data_parametric__) < __current_figure__ + || any (size (__plot_data_parametric__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) + __plot_data_parametric__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = []; +endif + +if (length (__plot_image_colormap__) < __current_figure__ + || any (size (__plot_image_colormap__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) + __plot_image_colormap__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = []; +endif + +if (length (__plot_image_dims__) < __current_figure__ + || any (size (__plot_image_dims__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) + __plot_image_dims__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = []; +endif + +if (length (__plot_fmtstr__) < __current_figure__ + || any (size (__plot_fmtstr__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) + __plot_fmtstr__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = []; +endif + +if (length (__plot_usingstr__) < __current_figure__ + || any (size (__plot_usingstr__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) + __plot_usingstr__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = []; +endif + +if (length (__plot_withstr__) < __current_figure__ + || any (size (__plot_withstr__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) + __plot_withstr__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = []; +endif + if (length (__plot_key_labels__) < __current_figure__ || any (size (__plot_key_labels__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)])) __plot_key_labels__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = [];
--- a/scripts/plot/__plt3__.m +++ b/scripts/plot/__plt3__.m @@ -33,21 +33,24 @@ ## David Bateman <dbateman@free.fr> ## May 25, 2006 -function __plt3__ (x, usingstr, fmtstr, keystr, withstr) +function __plt3__ (x, parametric, usingstr, fmtstr, keystr, withstr) if (nargin < 2) + parametric = false; + endif + if (nargin < 3) have_usingstr = false; usingstr = ""; else have_usingstr = true; endif - if (nargin < 3) + if (nargin < 4) fmtstr = ""; endif - if (nargin < 4) + if (nargin < 5) keystr = ""; endif - if (nargin < 5) + if (nargin < 6) withstr = ""; endif @@ -57,34 +60,25 @@ mxi = __multiplot_xi__(cf); myi = __multiplot_yi__(cf); - __setup_plot__ ("__gnuplot_splot__"); + __setup_plot__ ("splot"); j = __plot_data_offset__{cf}(mxi,myi); - loff = __plot_line_offset__{cf}(mxi,myi); - loff1 = loff; - __plot_data__{cf}{mxi,myi}{j} = x; - __plot_key_labels__{cf}{mxi,myi}{loff1++} = keystr; - - if (! have_usingstr) - usingstr = __make_using_clause__ (__plot_data__{cf}{mxi,myi}{j}); - endif + __plot_data__{cf}{mxi,myi}{j}{1} = x; + __plot_data_type__{cf}{mxi,myi}(j) = 3; + __plot_data_parametric__{cf}{mxi,myi}{j}{1} = parametric; + __plot_key_labels__{cf}{mxi,myi}{j}{1} = keystr; - __plot_command__{cf}{mxi,myi} ... - = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)}{%d} %s %s %s __plot_key_labels__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)}{%d} %s", - __plot_command__{cf}{mxi,myi}, - __plot_command_sep__, j++, usingstr, fmtstr, - gnuplot_command_title, loff++, withstr); - __plot_command_sep__ = ",\\\n"; + __plot_fmtstr__{cf}{mxi,myi}{j}{1} = fmtstr; + if (have_usingstr) + __plot_usingstr__{cf}{mxi,myi}{j}{1} = usingstr; + else + __plot_usingstr__{cf}{mxi,myi}{j}{1} = __make_using_clause__(x); + endif + __plot_withstr__{cf}{mxi,myi}{j}{1} = withstr; - __plot_data_offset__{cf}(mxi,myi) = j; - __plot_line_offset__{cf}(mxi,myi) = loff; + __plot_data_offset__{cf}(mxi,myi) = ++j; - if (__multiplot_mode__(cf)) - __gnuplot_raw__ ("clear\n"); - endif + __render_plot__ (); - if (! strcmp (__plot_command__{cf}{mxi,myi}, "__gnuplot_splot__")) - eval (__plot_command__{cf}{mxi,myi}); - endif endfunction
--- a/scripts/plot/__plt__.m +++ b/scripts/plot/__plt__.m @@ -31,7 +31,7 @@ mxi = __multiplot_xi__(cf); myi = __multiplot_yi__(cf); - __setup_plot__ ("__gnuplot_plot__"); + __setup_plot__ ("plot"); nargs = nargin (); @@ -39,8 +39,6 @@ k = 1; j = __plot_data_offset__{cf}(mxi,myi); - loff = __plot_line_offset__{cf}(mxi,myi); - loff1 = loff; x_set = false; y_set = false; @@ -56,8 +54,6 @@ next_arg = varargin{k++}; endif - have_data = false; - if (ischar (next_arg) || iscellstr (next_arg)) if (x_set) [fmt, keystr] = __pltopt__ (caller, next_arg); @@ -67,12 +63,16 @@ [tdata, tfmtstr, key] = __plt1__ (x, fmt, keystr); endif if (! isempty (tdata)) + for i = 1:numel (tdata) + __plot_usingstr__{cf}{mxi,myi}{j}{i} ... + = __make_using_clause__ (tdata{i}); + __plot_withstr__{cf}{mxi,myi}{j}{i} = ""; + endfor __plot_data__{cf}{mxi,myi}{j} = tdata; - for i = 1:length (key) - __plot_key_labels__{cf}{mxi,myi}{loff1++} = key{i}; - endfor - fmtstr = tfmtstr; - have_data = true; + __plot_data_type__{cf}{mxi,myi}(j) = 2; + __plot_fmtstr__{cf}{mxi,myi}{j} = tfmtstr; + __plot_key_labels__{cf}{mxi,myi}{j} = key; + j++; endif x_set = false; y_set = false; @@ -84,12 +84,16 @@ [fmt, keystr] = __pltopt__ (caller, {""}); [tdata, tfmtstr, key] = __plt2__ (x, y, fmt, keystr); if (! isempty (tdata)) + for i = 1:numel (tdata) + __plot_usingstr__{cf}{mxi,myi}{j}{i} ... + = __make_using_clause__ (tdata{i}); + __plot_withstr__{cf}{mxi,myi}{j}{i} = ""; + endfor __plot_data__{cf}{mxi,myi}{j} = tdata; - for i = 1:length (key) - __plot_key_labels__{cf}{mxi,myi}{loff1++} = key{i}; - endfor - fmtstr = tfmtstr; - have_data = true; + __plot_data_type__{cf}{mxi,myi}(j) = 2; + __plot_fmtstr__{cf}{mxi,myi}{j} = tfmtstr; + __plot_key_labels__{cf}{mxi,myi}{j} = key; + j++; endif x = next_arg; y_set = false; @@ -102,32 +106,11 @@ x_set = true; endif - if (have_data) - for i = 1:length (__plot_data__{cf}{mxi,myi}{j}) - usingstr = __make_using_clause__ (__plot_data__{cf}{mxi,myi}{j}{i}); - __plot_command__{cf}{mxi,myi} ... - = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)}{%d}{%d} %s %s %s __plot_key_labels__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)}{%d}", - __plot_command__{cf}{mxi,myi}, - __plot_command_sep__, j, i, usingstr, - fmtstr{i}, gnuplot_command_title, loff++); - __plot_command_sep__ = ",\\\n"; - endfor - j++; - endif - endwhile __plot_data_offset__{cf}(mxi,myi) = j; - __plot_line_offset__{cf}(mxi,myi) = loff; - if (__multiplot_mode__(cf)) - __gnuplot_raw__ ("clear\n"); - endif - - if (! strcmp (__plot_command__{cf}{mxi,myi}, "__gnuplot_plot__")) - __do_legend__ (); - eval (__plot_command__{cf}{mxi,myi}); - endif + __render_plot__ (); else msg = sprintf ("%s (y)\n", caller);
new file mode 100644 --- /dev/null +++ b/scripts/plot/__render_plot__.m @@ -0,0 +1,157 @@ +## Copyright (C) 2006 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +function __render_plot__ () + + __plot_globals__; + + cf = __current_figure__; + mxi = __multiplot_xi__(cf); + myi = __multiplot_yi__(cf); + + if (! isempty (__plot_data__{cf}{mxi,myi})) + + if (__multiplot_mode__(cf)) + __gnuplot_raw__ ("clear\n"); + endif + + have_image = false; + + for j = 1:length (__plot_data__{cf}{mxi,myi}) + if (__plot_data_type__{cf}{mxi,myi}(j) == 1) + have_image = true; + break; + endif + endfor + + if (have_image) + __gnuplot_raw__ ("set size ratio -1;\n"); + + cmap = __plot_image_colormap__{cf}{mxi,myi}; + + palette_size = rows (cmap); + __gnuplot_raw__ (sprintf ("set palette positive color model RGB maxcolors %i\n", + palette_size)); + + __gnuplot_raw__ ("set palette file \"-\"\n"); + tmp = round (1000 * cmap) / 1000; + tmp_rows = rows (tmp); + idx = (0:tmp_rows-1)'; + __gnuplot_raw__ (sprintf ("%d %.4g %.4g %.4g\n", [idx, tmp]')); + __gnuplot_raw__("e\n"); + + __gnuplot_raw__ ("set autoscale fix\n"); # "fix" is helpful for "a" hotkey + __gnuplot_raw__ ("set tics out\n"); + endif + + first = true; + + for j = 1:length (__plot_data__{cf}{mxi,myi}) + + if (j == 1) + first_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j); + this_plot_data_type = first_plot_data_type; + else + this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j); + if ((first_plot_data_type != 3 && this_plot_data_type == 3) + || (first_plot_data_type == 3 && this_plot_data_type != 3)) + error ("can't mix 2-d and 3-d data in the same plot"); + endif + endif + + for i = 1:length (__plot_data__{cf}{mxi,myi}{j}) + + if (first) + first = false; + __do_legend__ (); + if (first_plot_data_type == 3) + cmd = gnuplot_command_splot; + else + cmd = gnuplot_command_plot; + endif + __gnuplot_raw__ (sprintf ("%s ", cmd)); + else + __gnuplot_raw__ (",\\\n"); + endif + + if (this_plot_data_type == 1) + label = undo_string_escapes (__plot_key_labels__{cf}{mxi,myi}{j}{i}); + + tmp = __plot_image_dims__{cf}{mxi,myi}{j}{i}; + + x_dim = tmp(1); + y_dim = tmp(2); + x_origin = tmp(3); + y_origin = tmp(4); + dx = tmp(5); + dy = tmp(6); + + A = __plot_data__{cf}{mxi,myi}{j}{i}; + + ## Let the file be deleted when Octave exits or + ## `purge_tmp_files' is called. + [fid, binary_file_name, msg] ... + = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1); + + ## Gnuplot reads binary files very quickly. However, the + ## 'fwrite' below is much slower than using the current + ## '__gnuplot_plot__' command. + fwrite (fid, A(:), "float"); + fclose (fid); + + __gnuplot_raw__ (sprintf ("\"%s\" binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using 1 %s '%s' with image", + binary_file_name, x_dim, y_dim, x_origin, + y_origin, dx, dy, + gnuplot_command_title, label)); + else + usingstr = __plot_usingstr__{cf}{mxi,myi}{j}{i}; + fmtstr = __plot_fmtstr__{cf}{mxi,myi}{j}{i}; + withstr = __plot_withstr__{cf}{mxi,myi}{j}{i}; + + label = undo_string_escapes (__plot_key_labels__{cf}{mxi,myi}{j}{i}); + + __gnuplot_raw__ (sprintf ("'-' %s %s '%s' %s %s %s", usingstr, + gnuplot_command_title, label, fmtstr, + withstr)); + endif + endfor + endfor + + for j = 1:length (__plot_data__{cf}{mxi,myi}) + for i = 1:length (__plot_data__{cf}{mxi,myi}{j}) + this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j); + if (this_plot_data_type != 1) + if (this_plot_data_type == 3) + parametric = __plot_data_parametric__{cf}{mxi,myi}{j}{i}; + else + parametric = false; + endif + __gnuplot_send_inline_data__ (__plot_data__{cf}{mxi,myi}{j}{i}, + this_plot_data_type, parametric); + endif + endfor + endfor + + if (! first) + __gnuplot_raw__ ("\n"); + endif + + endif + +endfunction
--- a/scripts/plot/__setup_plot__.m +++ b/scripts/plot/__setup_plot__.m @@ -19,27 +19,6 @@ function __setup_plot__ (plotcmd) - __plot_globals__ - - cf = __current_figure__; - mxi = __multiplot_xi__(cf); - myi = __multiplot_yi__(cf); - - if (ishold ()) - cmd = __plot_command__{cf}{mxi,myi}; - if (isempty (cmd)) - cmd = plotcmd; - sep = ""; - else - sep = ",\\\n"; - endif - clear_data = false; - else - cmd = plotcmd; - sep = ""; - clear_data = true; - endif - - __init_plot_vars__ (cmd, sep, clear_data); + __init_plot_vars__ (! ishold ()); endfunction
--- a/scripts/plot/contour.m +++ b/scripts/plot/contour.m @@ -30,9 +30,11 @@ function contour (x, y, z, n) - ## FIXME -- these plot states should really just be set - ## temporarily, probably inside an unwind_protect block, but there is - ## no way to determine their current values. + __plot_globals__; + + cf = __current_figure__; + mxi = __multiplot_xi__(cf); + myi = __multiplot_yi__(cf); if (nargin == 1 || nargin == 2) z = x; @@ -57,9 +59,8 @@ error ("contour: levels must be a scalar or vector") ; endif __gnuplot_raw__ (command); - __gnuplot_set__ parametric; __gnuplot_raw__ ("set view 0, 0, 1, 1;\n"); - __plt3__ (z, "", "", "", [gnuplot_command_with, " l 1"]); + __plt3__ (z, true, "", "", "", [gnuplot_command_with, " l 1"]); else error ("contour: z of contour (z, levels) must be a matrix"); endif @@ -117,9 +118,8 @@ error ("contour: levels must be a scalar or vector") ; endif __gnuplot_raw__ (command); - __gnuplot_set__ parametric; __gnuplot_raw__ ("set view 0, 0, 1, 1;\n"); - __plt3__ (zz, "", "", "", [gnuplot_command_with, " l 1"]); + __plt3__ (zz, true, "", "", "", [gnuplot_command_with, " l 1"]); else error ("contour: x and y must be vectors and z must be a matrix"); endif
--- a/scripts/plot/mesh.m +++ b/scripts/plot/mesh.m @@ -32,6 +32,12 @@ function mesh (x, y, z) + __plot_globals__; + + cf = __current_figure__; + mxi = __multiplot_xi__(cf); + myi = __multiplot_yi__(cf); + if (nargin == 1) z = x; if (ismatrix (z)) @@ -79,11 +85,10 @@ __gnuplot_raw__ ("set surface;\n"); __gnuplot_raw__ ("set nocontour;\n"); __gnuplot_raw__ ("set nologscale;\n"); - __gnuplot_set__ parametric; __gnuplot_raw__ ("set view 60, 30, 1, 1;\n"); __gnuplot_raw__ ("set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n"); __gnuplot_raw__ ("set nocolorbox;\n"); - __plt3__ (zz, "", "", "", + __plt3__ (zz, true, "", "", "", sprintf ("%s line palette", gnuplot_command_with ())); else error ("mesh: x, y, and z must have same dimensions");
--- a/scripts/plot/plot3.m +++ b/scripts/plot/plot3.m @@ -165,6 +165,12 @@ function plot3 (varargin) + __plot_globals__; + + cf = __current_figure__; + mxi = __multiplot_xi__(cf); + myi = __multiplot_yi__(cf); + hold_state = ishold (); unwind_protect @@ -218,12 +224,11 @@ endif __gnuplot_raw__ ("set nohidden3d;\n") - __gnuplot_set__ parametric; __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... ([y; NaN*ones(1,size(y,2))])(:), ... ([z; NaN*ones(1,size(z,2))])(:)], - "u($1):($2):($3)", fmt{1}, key{1}); + true, "u($1):($2):($3)", fmt{1}, key{1}); hold ("on"); x_set = 0; @@ -256,11 +261,10 @@ endif __gnuplot_raw__ ("set nohidden3d;\n") - __gnuplot_set__ parametric; __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... ([y; NaN*ones(1,size(y,2))])(:), ... - ([z; NaN*ones(1,size(z,2))])(:)]); + ([z; NaN*ones(1,size(z,2))])(:)], true); hold ("on"); x = new; @@ -308,11 +312,10 @@ endif __gnuplot_raw__ ("set nohidden3d;\n") - __gnuplot_set__ parametric; __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... ([y; NaN*ones(1,size(y,2))])(:), ... - ([z; NaN*ones(1,size(z,2))])(:)]); + ([z; NaN*ones(1,size(z,2))])(:)], true); endif unwind_protect_cleanup
--- a/scripts/plot/replot.m +++ b/scripts/plot/replot.m @@ -26,22 +26,8 @@ function replot () - __plot_globals__; - - cf = __current_figure__; - mpmode = __multiplot_mode__(cf); - mxi = __multiplot_xi__(cf); - myi = __multiplot_yi__(cf); - cmd = __plot_command__{cf}{mxi,myi}; - if (nargin == 0) - if (! isempty (cmd)) - if (mpmode) - __gnuplot_raw__ ("clear\n"); - endif - __do_legend__ (); - eval (cmd); - endif + __render_plot__ (); else print_usage (); endif