# HG changeset patch # User John W. Eaton # Date 1289629505 18000 # Node ID c463aed850b0778fbb5d71f5d4f6e0c982bf88d8 # Parent 6f5d92d55acd3c6f253de945db48a0a6e27cffc3 allow legend and gcf to work when no figure is present diff -r 6f5d92d55acd -r c463aed850b0 scripts/ChangeLog --- a/scripts/ChangeLog Fri Nov 12 20:53:32 2010 -0500 +++ b/scripts/ChangeLog Sat Nov 13 01:25:05 2010 -0500 @@ -1,3 +1,9 @@ +2010-11-13 John W. Eaton + + * plot/gnuplot_drawnow.m (have_non_legend_axes): New function. + Use it to avoid errors if there are no axes. + * plot/legend.m: Avoid indexing beyond end of varargin array. + 2010-11-10 John W. Eaton * gethelp.cc: Eliminate special case for __DECCXX. diff -r 6f5d92d55acd -r c463aed850b0 scripts/plot/gnuplot_drawnow.m --- a/scripts/plot/gnuplot_drawnow.m Fri Nov 12 20:53:32 2010 -0500 +++ b/scripts/plot/gnuplot_drawnow.m Sat Nov 13 01:25:05 2010 -0500 @@ -302,9 +302,9 @@ fputs (plot_stream, "unset multiplot;\n"); flickering_terms = {"x11", "windows", "wxt", "dumb"}; if (! any (strcmp (term, flickering_terms)) - || (numel (findall (h, "type", "axes")) - - sum (strcmp (get (findall (h, "type", "axes"), "tag"), "legend"))) > 1 + || have_non_legend_axes (h) || numel (findall (h, "type", "image")) > 0) +1 fprintf (plot_stream, "%s\n", term_str); if (nargin == 5) if (! isempty (file)) @@ -377,4 +377,16 @@ ret = any (strcmpi ({"aqua", "dumb", "wxt", "x11", "windows", "pm"}, term)); endfunction - +function retval = have_non_legend_axes (h) + retval = false; + all_axes = findall (h, "type", "axes"); + if (! isempty (all_axes)) + n_all_axes = numel (all_axes); + all_axes_tags = get (all_axes, "tag"); + legend_axes = strcmp (all_axes_tags, "legend"); + if (! isempty (legend_axes)) + n_legend_axes = sum (legend_axes); + retval = (n_all_axes - n_legend_axes) > 1; + endif + endif +endfunction diff -r 6f5d92d55acd -r c463aed850b0 scripts/plot/legend.m --- a/scripts/plot/legend.m Fri Nov 12 20:53:32 2010 -0500 +++ b/scripts/plot/legend.m Sat Nov 13 01:25:05 2010 -0500 @@ -100,13 +100,18 @@ function [hlegend2, hobjects2, hplot2, text_strings2] = legend (varargin) - if (! ishandle (varargin {1}) || (strcmp (get (varargin {1}, "type"), "axes") - && ! strcmp (get (varargin {1}, "tag"), "legend"))) + if (nargin > 0 + && (! ishandle (varargin{1}) + || (strcmp (get (varargin{1}, "type"), "axes") + && ! strcmp (get (varargin{1}, "tag"), "legend")))) [ca, varargin, nargs] = __plt_get_axis_arg__ ("legend", varargin{:}); fig = get (ca, "parent"); else fig = get (0, "currentfigure"); - ca = get (fig, "currentaxes"); + if (isempty (fig)) + fig = gcf (); + endif + ca = gca (); endif if (strcmp (get (ca, "tag"), "plotyy")) @@ -118,10 +123,9 @@ endif endif - if (all (ishandle (varargin{1}))) + if (nargin > 0 && all (ishandle (varargin{1}))) kids = flipud (varargin{1}(:)); varargin(1) = []; - nargs = numel (varargin); else kids = ca; kids (strcmp (get (ca, "tag"), "legend")) = []; @@ -131,6 +135,7 @@ kids = [get(kids, "children"){:}](:); endif endif + nargs = numel (varargin); nkids = numel (kids); orientation = "default";