diff scripts/plot/legend.m @ 12402:766426578c14 release-3-4-x

legend.m: "legend off" should delete the legend object.
author Ben Abbott <bpabbott@mac.com>
date Sun, 06 Feb 2011 15:32:38 -0500
parents f16a5244d93a
children 4d30b4136a3e
line wrap: on
line diff
--- a/scripts/plot/legend.m	Sun Feb 06 17:17:12 2011 +0100
+++ b/scripts/plot/legend.m	Sun Feb 06 15:32:38 2011 -0500
@@ -81,9 +81,11 @@
 ##   Show legend on the plot
 ##
 ## @item "hide"
-## @itemx "off"
 ##   Hide legend on the plot
 ##
+## @itemx "toggle"
+##   Toggles between "hide" and "show"
+##
 ## @item "boxon"
 ##   Show a box around legend
 ##
@@ -95,6 +97,9 @@
 ##
 ## @item "right"
 ##   Place text to the right of the keys
+##
+## @itemx "off"
+##   Delete the legend object
 ## @end table
 ## @end deftypefn
 
@@ -217,7 +222,10 @@
       if (rows (arg) == 1)
         str = tolower (deblank (arg));
         switch (str)
-          case {"off", "hide"}
+          case {"off"}
+            delete (hlegend);
+            return
+          case {"hide"}
             show = "off";
             nargs--;
           case "show"
@@ -1091,4 +1099,14 @@
 %! hold off
 %! legend ({"sin(x)", "cos(x)"}, "location", "northeastoutside")
 
+%!demo
+%! clf
+%! x = 0:10;
+%! plot (x, rand (11));
+%! xlabel ("Indices")
+%! ylabel ("Random Values")
+%! title ("Legend ""off"" should delete the legend")
+%! legend (cellstr (num2str ((1:10)')), "location", "northeastoutside")
+%! legend off
+%! axis ([0, 10, 0 1])