From bug-request at octave dot org Thu Oct 13 12:49:25 2005 Subject: Unidentified subject! From: "John W. Eaton" To: cardoso at enst dot fr (Jean-Francois Cardoso) Cc: bug at octave dot org, cardoso@tsi.enst.fr Date: Thu, 13 Oct 2005 13:49:15 -0400 --5Np5O/6G4a Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit On 13-Oct-2005, Jean-Francois Cardoso wrote: | To: bug at octave dot org | Cc: cardoso at tsi dot enst dot fr | Subject: hold on + figure causes plot to fail (was: subwindow causes segfault ...) | | Bug report for Octave 2.9.3 configured for i686-pc-linux-gnu | | Description: | ----------- | | Some combinations of "hold on" and "figure" cause plot to fail. | See below for the specific conditions to trigger the bug. | | This happens in a 10-day old 2.9.3, but not in 2.1.71. | | The error message is | | error: must have something to plot | error: evaluating if command near line 106, column 5 | error: evaluating if command near line 32, column 3 | error: called from `__plt__' in file `/usr/local/share/octave/2.9.3/m/plot/__plt __.m' | error: called from `plot' in file `/usr/local/share/octave/2.9.3/m/plot/plot.m' | | | Repeat-By: | --------- | | save this code in an m-file | ================= | clear | figure(); | hold on | plot (randn(5,1)); | ================= | | and run it from a fresh instance of 2.9.3 with the --norc switch. The | above error will be triggered. | | However, the error is not triggered | | if | hold on is commented out. | or if | hold on is there but figure() is ommitted or replaced by figure(2) or figure(3) etc.... | BUT figure(1) does trigger the bug!!! | | Furthermore, | - with figure(1) repeated invocations of the script will always cause failures | - with figure() only the first invocation of the script will trigger the bug. | Subsequent invocations work ok. | | Looks like some nasty initialization problem.... I think the following patch may help, though you may need to update to the latest CVS sources to get things working. I've had these changes mostly written for a while, but had not committed them. They may introduce some other problems. If so, please report the trouble. The current plotting code is much to complex. I think it is time to get serious about implementing the handle graphics interface and rewrite these plot functions in terms of the handle graphics interface. jwe scripts/ChangeLog: 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__. --5Np5O/6G4a Content-Type: text/plain Content-Disposition: inline; filename="diffs" Content-Transfer-Encoding: 7bit Index: scripts/plot/__axis_label__.m =================================================================== RCS file: /cvs/octave/scripts/plot/__axis_label__.m,v retrieving revision 1.10 diff -u -r1.10 __axis_label__.m --- scripts/plot/__axis_label__.m 8 Sep 2005 01:40:58 -0000 1.10 +++ scripts/plot/__axis_label__.m 13 Oct 2005 17:47:39 -0000 at @ -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); Index: scripts/plot/__errplot__.m =================================================================== RCS file: /cvs/octave/scripts/plot/__errplot__.m,v retrieving revision 1.15 diff -u -r1.15 __errplot__.m --- scripts/plot/__errplot__.m 8 Jul 2005 15:25:43 -0000 1.15 +++ scripts/plot/__errplot__.m 13 Oct 2005 17:47:39 -0000 at @ -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); at @ -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"; at @ -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 Index: scripts/plot/__plot_globals__.m =================================================================== RCS file: /cvs/octave/scripts/plot/__plot_globals__.m,v retrieving revision 1.1 diff -u -r1.1 __plot_globals__.m --- scripts/plot/__plot_globals__.m 8 Jul 2005 15:25:43 -0000 1.1 +++ scripts/plot/__plot_globals__.m 13 Oct 2005 17:47:39 -0000 at @ -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__; at @ -29,29 +52,18 @@ __current_figure__ = 1; endif -if (length (__plot_data_offset__) < __current_figure__) - __plot_data_offset__(__current_figure__) = 1; +if (length (__plot_data_offset__) < __current_figure__ + || any (size (__plot_data_offset__{__current_figure__}) != [__multiplot_xi__, __multiplot_yi__])) + + __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = 1; endif -if (length (__plot_command__) < __current_figure__) - __plot_command__{__current_figure__} = ""; +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__) - __plot_data__{__current_figure__} = []; -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_data__) < __current_figure__ + || any (size (__plot_data__{__current_figure__}) != [__multiplot_xi__, __multiplot_yi__])) + __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = []; endif Index: scripts/plot/__plt__.m =================================================================== RCS file: /cvs/octave/scripts/plot/__plt__.m,v retrieving revision 1.35 diff -u -r1.35 __plt__.m --- scripts/plot/__plt__.m 8 Sep 2005 01:40:58 -0000 1.35 +++ scripts/plot/__plt__.m 13 Oct 2005 17:47:39 -0000 at @ -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; at @ -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; at @ -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; at @ -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 at @ -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 Index: scripts/plot/__setup_plot__.m =================================================================== RCS file: scripts/plot/__setup_plot__.m diff -N scripts/plot/__setup_plot__.m --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ scripts/plot/__setup_plot__.m 13 Oct 2005 17:47:39 -0000 at @ -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 Index: scripts/plot/axis.m =================================================================== RCS file: /cvs/octave/scripts/plot/axis.m,v retrieving revision 1.32 diff -u -r1.32 axis.m --- scripts/plot/axis.m 8 Sep 2005 01:40:58 -0000 1.32 +++ scripts/plot/axis.m 13 Oct 2005 17:47:39 -0000 at @ -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"); at @ -265,8 +265,7 @@ if (nargin > 1) axis (varargin{:}); elseif (automatic_replot) - ## No semicolon (see replot.m). - __gnuplot_replot__ + replot (); endif endfunction Index: scripts/plot/grid.m =================================================================== RCS file: /cvs/octave/scripts/plot/grid.m,v retrieving revision 1.26 diff -u -r1.26 grid.m --- scripts/plot/grid.m 8 Sep 2005 01:40:58 -0000 1.26 +++ scripts/plot/grid.m 13 Oct 2005 17:47:39 -0000 at @ -59,8 +59,7 @@ endif if (do_replot && automatic_replot) - ## No semicolon (see replot.m). - __gnuplot_replot__ + replot (); endif endfunction Index: scripts/plot/plot_border.m =================================================================== RCS file: /cvs/octave/scripts/plot/plot_border.m,v retrieving revision 1.23 diff -u -r1.23 plot_border.m --- scripts/plot/plot_border.m 8 Sep 2005 01:40:58 -0000 1.23 +++ scripts/plot/plot_border.m 13 Oct 2005 17:47:39 -0000 at @ -111,8 +111,7 @@ endif if (automatic_replot) - ## No semicolon (see replot.m). - __gnuplot_replot__ + replot (); endif endfunction Index: scripts/plot/replot.m =================================================================== RCS file: /cvs/octave/scripts/plot/replot.m,v retrieving revision 1.3 diff -u -r1.3 replot.m --- scripts/plot/replot.m 26 Apr 2005 19:24:31 -0000 1.3 +++ scripts/plot/replot.m 13 Oct 2005 17:47:39 -0000 at @ -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 Index: scripts/plot/shg.m =================================================================== RCS file: /cvs/octave/scripts/plot/shg.m,v retrieving revision 1.17 diff -u -r1.17 shg.m --- scripts/plot/shg.m 26 Apr 2005 19:24:31 -0000 1.17 +++ scripts/plot/shg.m 13 Oct 2005 17:47:39 -0000 at @ -36,6 +36,6 @@ warning ("shg: ignoring extra arguments"); endif - __gnuplot_replot__ + replot (); endfunction Index: scripts/plot/subplot.m =================================================================== RCS file: /cvs/octave/scripts/plot/subplot.m,v retrieving revision 1.27 diff -u -r1.27 subplot.m --- scripts/plot/subplot.m 26 Apr 2005 19:24:31 -0000 1.27 +++ scripts/plot/subplot.m 13 Oct 2005 17:47:39 -0000 at @ -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)"); at @ -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", Index: scripts/plot/title.m =================================================================== RCS file: /cvs/octave/scripts/plot/title.m,v retrieving revision 1.26 diff -u -r1.26 title.m --- scripts/plot/title.m 8 Sep 2005 01:40:58 -0000 1.26 +++ scripts/plot/title.m 13 Oct 2005 17:47:39 -0000 at @ -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"); Index: scripts/plot/top_title.m =================================================================== RCS file: /cvs/octave/scripts/plot/top_title.m,v retrieving revision 1.21 diff -u -r1.21 top_title.m --- scripts/plot/top_title.m 8 Sep 2005 01:40:58 -0000 1.21 +++ scripts/plot/top_title.m 13 Oct 2005 17:47:39 -0000 at @ -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"); --5Np5O/6G4a-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------