Mercurial > hg > octave-lyh
changeset 14780:1d83d1539b2b
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.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Mon, 18 Jun 2012 19:54:03 -0400 |
parents | 1230d5d58d2d |
children | e190f6da40f6 |
files | scripts/plot/plotyy.m |
diffstat | 1 files changed, 32 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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;