diff scripts/plot/plotyy.m @ 8237:52f2fba4f3f8

Test that an axis handle actually is one before setting it in plotyy
author David Bateman <dbateman@free.fr>
date Mon, 20 Oct 2008 13:22:17 +0100
parents f6ca8ff51818
children be9b14945774
line wrap: on
line diff
--- a/scripts/plot/plotyy.m
+++ b/scripts/plot/plotyy.m
@@ -99,7 +99,10 @@
   unwind_protect
     [ax, h1, h2] = __plotyy__ (ax, varargin{:});
   unwind_protect_cleanup
-    axes (oldh);
+    ## Only change back to the old axis if we didn't delete it
+    if (ishandle(oldh) && strcmp (get (oldh, "type"), "axes"))
+      axes (oldh);
+    endif
   end_unwind_protect
 
   if (nargout > 0)
@@ -124,7 +127,11 @@
 
   xlim = [min([x1(:); x2(:)]), max([x1(:); x2(:)])];
 
-  axes (ax(1));
+  if (ishandle(ax(1)) && strcmp (get (ax(1), "type"), "axes"))
+    axes (ax(1));
+  else
+    ax(1) = axes ();
+  endif
   newplot ();
   h1 = feval (fun1, x1, y1);
 
@@ -133,7 +140,12 @@
 
   cf = gcf ();
   set (cf, "nextplot", "add");
-  axes (ax(2));
+
+  if (ishandle(ax(2)) && strcmp (get (ax(2), "type"), "axes"))
+    axes (ax(2));
+  else
+    ax(2) = axes ();
+  endif
   newplot ();
 
   colors = get (ax(1), "colororder");