plotyy.m: Fix compatibility with subplot.
1.1 --- a/scripts/ChangeLog Tue Jun 16 06:43:56 2009 +0200
1.2 +++ b/scripts/ChangeLog Tue Jun 16 06:43:56 2009 +0200
1.3 @@ -1,3 +1,8 @@
1.4 +2009-06-14 Ben Abbott <bpabbott@mac.com>
1.5 +
1.6 + * plot/plotyy.m: Fix compatibility with subplot, add listeners for
1.7 + dataaspectratio, and add a demo.
1.8 +
1.9 2009-06-14 Eric Chassande-Mottin <echassandemottin@gmail.com>
1.10
1.11 * plot/plotyy.m: Correct behavior when there is no currentfigure.
2.1 --- a/scripts/plot/plotyy.m Tue Jun 16 06:43:56 2009 +0200
2.2 +++ b/scripts/plot/plotyy.m Tue Jun 16 06:43:56 2009 +0200
2.3 @@ -75,7 +75,14 @@
2.4 if (isempty (f))
2.5 f = figure ();
2.6 endif
2.7 - ax = get (f, "children");
2.8 + ca = get (f, "currentaxes");
2.9 + if (isempty (ca))
2.10 + ax = [];
2.11 + elseif (strcmp (get (ca, "tag"), "plotyy"));
2.12 + ax = get (ca, "__plotyy_axes__");
2.13 + else
2.14 + ax = ca;
2.15 + endif
2.16 if (length (ax) > 2)
2.17 for i = 3 : length (ax)
2.18 delete (ax (i));
2.19 @@ -175,11 +182,17 @@
2.20 addlistener (ax(2), "position", {@update_position, ax(1)});
2.21 addlistener (ax(1), "view", {@update_position, ax(2)});
2.22 addlistener (ax(2), "view", {@update_position, ax(1)});
2.23 + addlistener (ax(1), "dataaspectratio", {@update_position, ax(2)});
2.24 + addlistener (ax(2), "dataaspectratio", {@update_position, ax(1)});
2.25
2.26 ## Tag the plotyy axes, so we can use that information
2.27 ## not to mirror the y axis tick marks
2.28 set (ax, "tag", "plotyy")
2.29
2.30 + ## Store the axes handles for the sister axes.
2.31 + addproperty ("__plotyy_axes__", ax(1), "data", ax);
2.32 + addproperty ("__plotyy_axes__", ax(2), "data", ax);
2.33 +
2.34 endfunction
2.35
2.36 %!demo
2.37 @@ -192,6 +205,19 @@
2.38 %! ylabel (ax(1), "Axis 1");
2.39 %! ylabel (ax(2), "Axis 2");
2.40
2.41 +%!demo
2.42 +%! clf
2.43 +%! x = linspace (-1, 1, 201);
2.44 +%! subplot (2, 2, 1)
2.45 +%! plotyy (x, sin(pi*x), x, 10*cos(pi*x))
2.46 +%! subplot (2, 2, 2)
2.47 +%! surf (peaks (25))
2.48 +%! subplot (2, 2, 3)
2.49 +%! contour (peaks (25))
2.50 +%! subplot (2, 2, 4)
2.51 +%! plotyy (x, 10*sin(2*pi*x), x, cos(2*pi*x))
2.52 +%! axis square
2.53 +
2.54 function deleteplotyy (h, d, ax2, t2)
2.55 if (ishandle (ax2) && strcmp (get (ax2, "type"), "axes") &&
2.56 (isempty (gcbf()) || strcmp (get (gcbf(), "beingdeleted"),"off")) &&
2.57 @@ -210,10 +236,16 @@
2.58 recursion = true;
2.59 position = get (h, "position");
2.60 view = get (h, "view");
2.61 + dataaspectratio = get (h, "dataaspectratio");
2.62 oldposition = get (ax2, "position");
2.63 oldview = get (ax2, "view");
2.64 - if (! (isequal (position, oldposition) && isequal (view, oldview)))
2.65 - set (ax2, "position", position, "view", view);
2.66 + olddataaspectratio = get (ax2, "dataaspectratio");
2.67 + if (! (isequal (position, oldposition)
2.68 + && isequal (view, oldview)
2.69 + && isequal (dataaspectratio, olddataaspectratio)))
2.70 + set (ax2, "position", position,
2.71 + "view", view,
2.72 + "dataaspectratio", dataaspectratio);
2.73 endif
2.74 unwind_protect_cleanup
2.75 recursion = false;