# HG changeset patch # User Ben Abbott # Date 1340063643 14400 # Node ID 1d83d1539b2b696388367ba15da6d4dc8a2e1b70 # Parent 1230d5d58d2d1796be72d127f306449e4488b913 Fix plotyy to function as expected with "hold on" (Bug # 36508) * scripts/plot/plotyy.m: Add new subfunction update_nextplot(). Synchronize the "nextplot" properties. Add demo. diff --git a/scripts/plot/plotyy.m b/scripts/plot/plotyy.m --- a/scripts/plot/plotyy.m +++ b/scripts/plot/plotyy.m @@ -91,6 +91,7 @@ ax = ax(1:2); elseif (length (ax) == 1) ax(2) = axes (); + set (ax(2), "nextplot", get (ax(1), "nextplot")) elseif (isempty (ax)) ax(1) = axes (); ax(2) = axes (); @@ -156,6 +157,7 @@ axes (ax(2)); else ax(2) = axes (); + set (ax(2), "nextplot", get (ax(1), "nextplot")) endif newplot (); @@ -172,7 +174,6 @@ set (ax(2), "yaxislocation", "right"); set (ax(2), "ycolor", getcolor (h2(1))); - if (strcmp (get(ax(1), "activepositionproperty"), "position")) set (ax(2), "position", get (ax(1), "position")); else @@ -208,6 +209,8 @@ addlistener (ax(2), "plotboxaspectratio", {@update_position, ax(1)}); addlistener (ax(1), "plotboxaspectratiomode", {@update_position, ax(2)}); addlistener (ax(2), "plotboxaspectratiomode", {@update_position, ax(1)}); + addlistener (ax(1), "nextplot", {@update_nextplot, ax(2)}); + addlistener (ax(2), "nextplot", {@update_nextplot, ax(1)}); ## Store the axes handles for the sister axes. if (ishandle (ax(1)) && ! isprop (ax(1), "__plotyy_axes__")) @@ -261,10 +264,24 @@ %! clf; %! x = linspace (-1, 1, 201); %! hax = plotyy (x, sin (pi*x), x, cos (pi*x)); -%! ylabel ('Blue on the Left'); +%! ylabel (hax(1), 'Blue on the Left'); %! ylabel (hax(2), 'Green on the Right'); %! xlabel ('xlabel'); +%!demo +%! clf +%! hold on +%! t = (0:0.1:9); +%! x = sin (t); +%! y = 5 * cos (t); +%! [hax, h1, h2] = plotyy (t, x, t, y); +%! [~, h3, h4] = plotyy (t+1, x, t+1, y); +%! set ([h3, h4], "linestyle", "--") +%! xlabel (hax(1), 'xlabel') +%! title (hax(2), 'title') +%! ylabel (hax(1), 'Left axis is Blue') +%! ylabel (hax(2), 'Right axis is Green') + function deleteplotyy (h, d, ax2, t2) if (ishandle (ax2) && strcmp (get (ax2, "type"), "axes") && (isempty (gcbf()) || strcmp (get (gcbf(), "beingdeleted"),"off")) @@ -274,6 +291,19 @@ endif endfunction +function update_nextplot (h, d, ax2) + persistent recursion = false; + prop = "nextplot"; + if (! recursion) + unwind_protect + recursion = true; + set (ax2, prop, get (h, prop)); + unwind_protect_cleanup + recursion = false; + end_unwind_protect + endif +endfunction + function update_position (h, d, ax2) persistent recursion = false;