# HG changeset patch # User jwe # Date 1129225879 0 # Node ID b2e882e8b68b449dd86387a044d6226eabb7b8c3 # Parent 179096e8e57fcb58c6e39491afbfd81e349e7693 [project @ 2005-10-13 17:51:19 by jwe] diff -r 179096e8e57f -r b2e882e8b68b scripts/ChangeLog --- a/scripts/ChangeLog Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/ChangeLog Thu Oct 13 17:51:19 2005 +0000 @@ -1,3 +1,23 @@ +2005-10-13 John W. Eaton + + * plot/__plt__.m, plot/__errplot__.m, plot/replot.m: + If in multiplot mode, clear plot before issuing new plot command. + + * plot/__setup_plot__.m: New function. + * plot/__plt__.m, plot__errplot__.m: Use it. + Handle multiplot data and offsets here. + + * plot/__plot_globals__.m: Also keep track of multiplot options. + Move initialization to __setup_plot__.m. + + * plot/subplot.m: Multiplot globals now in __plot_globals__.m. + Don't reset gnuplot_command_replot. + + * plot/replot.m: Handle multiplot data and offsets here. + * plot__axis_label__.m, plot/axis.m, plot/grid.m, + plot/plot_border.m, plot/plot.m, plot/plot_title.m, + plot/top_title.m: Call replot, not __gnuplot_replot__. + 2005-10-12 John W. Eaton * plot/figure.m: Handle __current_figure__, not gnuplot details. diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/__axis_label__.m --- a/scripts/plot/__axis_label__.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/__axis_label__.m Thu Oct 13 17:51:19 2005 +0000 @@ -33,8 +33,7 @@ __gnuplot_raw__ (sprintf ("set %s \"%s\";\n", caller, undo_string_escapes (text))); if (automatic_replot) - ## No semicolon (see replot.m). - __gnuplot_replot__ + replot (); endif else error ("%s: text must be a string", caller); diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/__errplot__.m --- a/scripts/plot/__errplot__.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/__errplot__.m Thu Oct 13 17:51:19 2005 +0000 @@ -38,11 +38,13 @@ __plot_globals__; + __setup_plot__; + if (nargin < 3 || nargin > 7) # at least three data arguments needed usage ("__errplot__ (fmt, arg1, ...)"); endif - j = __plot_data_offset__(__current_figure__); + j = __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__); fmt = __pltopt__ ("__errplot__", fstr); @@ -72,11 +74,11 @@ a2(:,i)-a5(:,i), a2(:,i)+a6(:,i)]; endswitch - __plot_data__{__current_figure__}{j} = tmp; + __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j} = tmp; - __plot_command__{__current_figure__} \ - = sprintf ("%s%s __plot_data__{__current_figure__}{%d} %s", - __plot_command__{__current_figure__}, + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} \ + = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{%d} %s", + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}, __plot_command_sep__, j, ifmt); __plot_command_sep__ = ",\\\n"; @@ -84,10 +86,13 @@ endfor - __plot_data_offset__(__current_figure__) = j; + __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = j; - if (! isempty (__plot_command__{__current_figure__})) - eval (__plot_command__{__current_figure__}); + if (! isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__})) + if (__multiplot_mode__) + __gnuplot_raw__ ("clear\n"); + endif + eval (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}); endif endfunction diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/__plot_globals__.m --- a/scripts/plot/__plot_globals__.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/__plot_globals__.m Thu Oct 13 17:51:19 2005 +0000 @@ -19,6 +19,29 @@ ## This is a script file shared by __plt__ and __errplot__. +## global variables to keep track of multiplot options + +global __multiplot_mode__ = 0; +global __multiplot_xsize__; +global __multiplot_ysize__; +global __multiplot_xn__; +global __multiplot_yn__; +global __multiplot_xi__; +global __multiplot_yi__; +global __multiplot_scale__; + +if (isempty (__multiplot_scale__)) + __multiplot_scale__ = [1, 1]; +endif + +if (isempty (__multiplot_xi__)) + __multiplot_xi__ = 1; +endif + +if (isempty (__multiplot_yi__)) + __multiplot_yi__ = 1; +endif + global __current_figure__; global __plot_data_offset__; global __plot_command__; @@ -29,29 +52,18 @@ __current_figure__ = 1; endif -if (length (__plot_data_offset__) < __current_figure__) - __plot_data_offset__(__current_figure__) = 1; -endif +if (length (__plot_data_offset__) < __current_figure__ + || any (size (__plot_data_offset__{__current_figure__}) != [__multiplot_xi__, __multiplot_yi__])) -if (length (__plot_command__) < __current_figure__) - __plot_command__{__current_figure__} = ""; -endif - -if (length (__plot_data__) < __current_figure__) - __plot_data__{__current_figure__} = []; + __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = 1; endif -if (ishold ()) - if (isempty (__plot_command__{__current_figure__})) - __plot_command__{__current_figure__} = "__gnuplot_plot__"; - __plot_command_sep__ = ""; - else - gp_cmd = __plot_command__{__current_figure__}; - __plot_command_sep__ = ",\\\n"; - endif -else - __plot_command__{__current_figure__} = "__gnuplot_plot__"; - __plot_command_sep__ = ""; - __plot_data__{__current_figure__} = []; - __plot_data_offset__(__current_figure__) = 1; +if (length (__plot_command__) < __current_figure__ + || any (size (__plot_command__{__current_figure__}) != [__multiplot_xi__, __multiplot_yi__])) + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = ""; endif + +if (length (__plot_data__) < __current_figure__ + || any (size (__plot_data__{__current_figure__}) != [__multiplot_xi__, __multiplot_yi__])) + __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = []; +endif diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/__plt__.m --- a/scripts/plot/__plt__.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/__plt__.m Thu Oct 13 17:51:19 2005 +0000 @@ -27,12 +27,14 @@ __plot_globals__; + __setup_plot__; + nargs = nargin (); if (nargs > 1) k = 1; - j = __plot_data_offset__(__current_figure__); + j = __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__); x_set = false; y_set = false; @@ -54,9 +56,9 @@ if (x_set) fmt = __pltopt__ (caller, next_arg); if (y_set) - [__plot_data__{__current_figure__}{j}, fmtstr] = __plt2__ (x, y, fmt); + [__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}, fmtstr] = __plt2__ (x, y, fmt); else - [__plot_data__{__current_figure__}{j}, fmtstr] = __plt1__ (x, fmt); + [__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}, fmtstr] = __plt1__ (x, fmt); endif have_data = true; x_set = false; @@ -67,7 +69,7 @@ elseif (x_set) if (y_set) fmt = __pltopt__ (caller, ""); - [__plot_data__{__current_figure__}{j}, fmtstr] = __plt2__ (x, y, fmt); + [__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}, fmtstr] = __plt2__ (x, y, fmt); have_data = true; x = next_arg; y_set = false; @@ -81,18 +83,18 @@ endif if (have_data) - if (iscell (__plot_data__{__current_figure__}{j})) - for i = 1:length (__plot_data__{__current_figure__}{j}) - __plot_command__{__current_figure__} \ - = sprintf ("%s%s __plot_data__{__current_figure__}{%d}{%d} %s", - __plot_command__{__current_figure__}, + if (iscell (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j})) + for i = 1:length (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}) + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} \ + = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{%d}{%d} %s", + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}, __plot_command_sep__, j, i, fmtstr{i}); __plot_command_sep__ = ",\\\n"; endfor else - __plot_command__{__current_figure__} \ - = sprintf ("%s%s __plot_data__{__current_figure__}{%d} %s", - __plot_command__{__current_figure__}, + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} \ + = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{%d} %s", + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}, __plot_command_sep__, j, fmtstr); __plot_command_sep__ = ",\\\n"; endif @@ -101,10 +103,13 @@ endwhile - __plot_data_offset__(__current_figure__) = j; + __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = j; - if (! isempty (__plot_command__{__current_figure__})) - eval (__plot_command__{__current_figure__}); + if (! isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__})) + if (__multiplot_mode__) + __gnuplot_raw__ ("clear\n"); + endif + eval (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}); endif else diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/__setup_plot__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/__setup_plot__.m Thu Oct 13 17:51:19 2005 +0000 @@ -0,0 +1,32 @@ +## Copyright (C) 2005 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. + +if (ishold ()) + if (isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__})) + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = "__gnuplot_plot__"; + __plot_command_sep__ = ""; + else + __plot_command_sep__ = ",\\\n"; + endif +else + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = "__gnuplot_plot__"; + __plot_command_sep__ = ""; + __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = []; + __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = 1; +endif diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/axis.m --- a/scripts/plot/axis.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/axis.m Thu Oct 13 17:51:19 2005 +0000 @@ -170,7 +170,7 @@ __gnuplot_raw__ ("set zrange [] writeback;\n"); ## XXX FIXME XXX if writeback were set in plot, no need to replot here. ## No semicolon (see replot.m). - __gnuplot_replot__ + replot (); __gnuplot_raw__ ("set noautoscale x;\n"); __gnuplot_raw__ ("set noautoscale y;\n"); __gnuplot_raw__ ("set noautoscale z;\n"); @@ -265,8 +265,7 @@ if (nargin > 1) axis (varargin{:}); elseif (automatic_replot) - ## No semicolon (see replot.m). - __gnuplot_replot__ + replot (); endif endfunction diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/grid.m --- a/scripts/plot/grid.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/grid.m Thu Oct 13 17:51:19 2005 +0000 @@ -59,8 +59,7 @@ endif if (do_replot && automatic_replot) - ## No semicolon (see replot.m). - __gnuplot_replot__ + replot (); endif endfunction diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/plot_border.m --- a/scripts/plot/plot_border.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/plot_border.m Thu Oct 13 17:51:19 2005 +0000 @@ -111,8 +111,7 @@ endif if (automatic_replot) - ## No semicolon (see replot.m). - __gnuplot_replot__ + replot (); endif endfunction diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/replot.m --- a/scripts/plot/replot.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/replot.m Thu Oct 13 17:51:19 2005 +0000 @@ -26,10 +26,15 @@ function replot () + __plot_globals__; + if (nargin == 0) - ## No semicolon following the __gnuplot_replot__ line unless you - ## also fix gplot.l to allow it. - __gnuplot_replot__ + if (! isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__})) + if (__multiplot_mode__) + __gnuplot_raw__ ("clear\n"); + endif + eval (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}); + endif else usage ("replot ()"); endif diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/shg.m --- a/scripts/plot/shg.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/shg.m Thu Oct 13 17:51:19 2005 +0000 @@ -36,6 +36,6 @@ warning ("shg: ignoring extra arguments"); endif - __gnuplot_replot__ + replot (); endfunction diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/subplot.m --- a/scripts/plot/subplot.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/subplot.m Thu Oct 13 17:51:19 2005 +0000 @@ -82,20 +82,7 @@ function subplot (rows, columns, index) - ## global variables to keep track of multiplot options - - global __multiplot_mode__ = 0; - global __multiplot_xsize__; - global __multiplot_ysize__; - global __multiplot_xn__; - global __multiplot_yn__; - global __multiplot_xi__; - global __multiplot_yi__; - global __multiplot_scale__; - - if (isempty (__multiplot_scale__)) - __multiplot_scale__ = [1, 1]; - endif + __plot_globals__; if (nargin != 3 && nargin != 1) usage ("subplot (rows, columns, index) or subplot (rcn)"); @@ -155,8 +142,6 @@ __multiplot_xsize__ = __multiplot_scale__(1) ./ columns; __multiplot_ysize__ = __multiplot_scale__(2) ./ rows; - gnuplot_command_replot = "cle;rep"; - __gnuplot_raw__ ("set multiplot;\n"); __gnuplot_raw__ (sprintf ("set size %g, %g;\n", diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/title.m --- a/scripts/plot/title.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/title.m Thu Oct 13 17:51:19 2005 +0000 @@ -37,8 +37,7 @@ __gnuplot_raw__ (sprintf ("set title \"%s\";\n", undo_string_escapes (text))); if (automatic_replot) - ## No semicolon (see replot.m). - __gnuplot_replot__ + replot (); endif else error ("title: text must be a string"); diff -r 179096e8e57f -r b2e882e8b68b scripts/plot/top_title.m --- a/scripts/plot/top_title.m Thu Oct 13 16:58:23 2005 +0000 +++ b/scripts/plot/top_title.m Thu Oct 13 17:51:19 2005 +0000 @@ -39,8 +39,7 @@ __gnuplot_raw__ (sprintf ("set top_title \"%s\";\n", undo_string_escapes (text))); if (automatic_replot) - ## No semicolon (see replot.m). - __gnuplot_replot__ + replot (); endif else error ("error: top_title: text must be a string");