changeset 13221:cc6e9425c04e stable

errorbar plots can now accept a legend key (Bug #33580). __errplot__.m: Borrow code from __plt__ for putting legend on plot when it is included in linespec.
author Rik <octave@nomad.inbox5.com>
date Sun, 25 Sep 2011 16:24:07 -0700
parents 88bd1d1d6657
children 0a67c717c652
files scripts/plot/private/__errplot__.m
diffstat 1 files changed, 35 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/private/__errplot__.m	Sat Sep 24 11:04:24 2011 -0500
+++ b/scripts/plot/private/__errplot__.m	Sun Sep 25 16:24:07 2011 -0700
@@ -31,7 +31,7 @@
     print_usage ();
   endif
 
-  [fmt, key] = __pltopt__ ("__errplot__", fstr);
+  [fmt, valid] = __pltopt__ ("__errplot__", fstr);
 
   [len, nplots] = size (varargin{1});
   h = [];
@@ -74,7 +74,7 @@
     switch (numel(varargin))
       case 2
         ydata = varargin{1}(:,i);
-        xdata = 1:numel(ydata);
+        xdata = 1:numel (ydata);
         if (strcmp (ifmt, "xerr") || strcmp (ifmt, "box"))
           xldata = varargin{2}(:,i);
           xudata = ldata;
@@ -86,12 +86,12 @@
           xldata = [];
           xudata = [];
         else
-          error ("errorbar: 2 column errorplot is only valid or xerr or yerr");
+          error ("errorbar: 2 column errorplot is only valid for xerr or yerr");
         endif
       case 3
         if (strcmp (ifmt, "boxxy") || strcmp (ifmt, "xyerr"))
           ydata = varargin{1}(:,i);
-          xdata = 1:numel(ydata);
+          xdata = 1:numel (ydata);
           xldata = varargin{2}(:,i);
           xudata = xldata;
           ldata = varargin{3}(:,i);
@@ -146,7 +146,7 @@
           error ("errorbar: error plot with 6 columns only valid for boxxy and xyerr");
         endif
       otherwise
-        error ("errorbar: error plot requires 2, 3, 4 or 6 arguments");
+        error ("errorbar: error plot requires 2, 3, 4, or 6 arguments");
     endswitch
 
     addproperty ("xdata", hg, "data", xdata(:));
@@ -193,6 +193,34 @@
 
   endfor
 
+  ## Process legend key
+  if (! isempty (fmt.key))    
+    hlegend = [];
+    fkids = get (gcf(), "children");
+    for i = 1 : numel (fkids)
+      if (ishandle (fkids(i)) && strcmp (get (fkids(i), "type"), "axes")
+          && (strcmp (get (fkids(i), "tag"), "legend")))
+        udata = get (fkids(i), "userdata");
+        if (! isempty (intersect (udata.handle, gca ())))
+          hlegend = fkids (i);
+          break;
+        endif
+      endif
+    endfor
+
+    if (isempty (hlegend))
+      hlgnd = [];
+      tlgnd = {};
+    else
+      [hlgnd, tlgnd] = __getlegenddata__ (hlegend);
+    endif
+ 
+    hlgnd(end+1) = hg;
+    tlgnd(end+1) = fmt.key;
+
+    legend (gca(), hlgnd, tlgnd);
+  end 
+
 endfunction
 
 function [xdata, ydata] = errorbar_data (xdata, ydata, ldata, udata,
@@ -259,8 +287,10 @@
   else
     error ("errorbar: valid error bar types are xerr, yerr, boxxy, and xyerr");
   endif
+
   xdata = xdata.'(:);
   ydata = ydata.'(:);
+
 endfunction
 
 function update_props (hg, dummy, hl)