Mercurial > octave
changeset 24428:3472c6760ad2
Update plotyy implementation.
* plotyy.m: Change special axes property "__plotyy_axes__" to return
a row vector. Turn off "zliminclude" on special hidden text objects
used to trigger deletion callbacks. Remove excessive checking for
validity of handles in __plotyy_axes__.
* legend.m: Simplify extracting handles from __plotyy_axes__ property.
* copyobj.m: Add new demo which uses plotyy to test that copyobj
handles special __plotyy_axes__ property correctly.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 18 Dec 2017 17:30:48 -0800 |
parents | 51ead71394bc |
children | 127110fc42c6 |
files | scripts/plot/appearance/legend.m scripts/plot/draw/plotyy.m scripts/plot/util/copyobj.m |
diffstat | 3 files changed, 42 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/appearance/legend.m Mon Dec 18 16:19:37 2017 -0800 +++ b/scripts/plot/appearance/legend.m Mon Dec 18 17:30:48 2017 -0800 @@ -137,12 +137,8 @@ ## Special handling for plotyy which has two axes objects if (ishghandle (ca) && isprop (ca, "__plotyy_axes__")) plty = get (ca, "__plotyy_axes__"); - if (isscalar (plty) && ishghandle (plty)) - ca = [ca, plty]; - elseif (iscell (plty)) - ca = [ca, plty{:}]; - elseif (all (ishghandle (plty))) - ca = [ca, plty(:).']; + if (all (ishghandle (plty))) + ca = [ca, plty.']; else error ("legend.m: This should not happen. File a bug report."); endif
--- a/scripts/plot/draw/plotyy.m Mon Dec 18 16:19:37 2017 -0800 +++ b/scripts/plot/draw/plotyy.m Mon Dec 18 17:30:48 2017 -0800 @@ -76,10 +76,10 @@ ## FIXME: Second conditional test shouldn't be required. ## 'cla reset' needs to delete user properties like __plotyy_axes__. if (isprop (hax, "__plotyy_axes__") - && isaxes (get (hax, "__plotyy_axes__")) == [true true]) + && isaxes (get (hax, "__plotyy_axes__")) == [true; true]) hax = get (hax, "__plotyy_axes__"); else - hax(2) = axes ("nextplot", get (hax(1), "nextplot")); + hax = [hax; axes("nextplot", get (hax(1), "nextplot"))]; endif [axtmp, h1tmp, h2tmp] = __plotyy__ (hax, varargin{:}); @@ -158,10 +158,13 @@ ## also remove the other axis t1 = text (0, 0, "", "parent", ax(1), "tag", "plotyy", "visible", "off", "handlevisibility", "off", - "xliminclude", "off", "yliminclude", "off"); + "xliminclude", "off", "yliminclude", "off", + "zliminclude", "off"); + t2 = text (0, 0, "", "parent", ax(2), "tag", "plotyy", "visible", "off", "handlevisibility", "off", - "xliminclude", "off", "yliminclude", "off"); + "xliminclude", "off", "yliminclude", "off", + "zliminclude", "off"); set (t1, "deletefcn", {@deleteplotyy, ax(2), t2}); set (t2, "deletefcn", {@deleteplotyy, ax(1), t1}); @@ -183,21 +186,17 @@ addlistener (ax(2), "nextplot", {@update_nextplot, ax(1)}); ## Store the axes handles for the sister axes. - if (ishghandle (ax(1)) && ! isprop (ax(1), "__plotyy_axes__")) + if (! isprop (ax(1), "__plotyy_axes__")) addproperty ("__plotyy_axes__", ax(1), "data"); set (ax(1), "__plotyy_axes__", ax); - elseif (ishghandle (ax(1))) - set (ax(1), "__plotyy_axes__", ax); else - error ("plotyy.m: This shouldn't happen. File a bug report."); + set (ax(1), "__plotyy_axes__", ax); endif - if (ishghandle (ax(2)) && ! isprop (ax(2), "__plotyy_axes__")) + if (! isprop (ax(2), "__plotyy_axes__")) addproperty ("__plotyy_axes__", ax(2), "data"); set (ax(2), "__plotyy_axes__", ax); - elseif (ishghandle (ax(2))) + else set (ax(2), "__plotyy_axes__", ax); - else - error ("plotyy.m: This shouldn't happen. File a bug report."); endif endfunction
--- a/scripts/plot/util/copyobj.m Mon Dec 18 16:19:37 2017 -0800 +++ b/scripts/plot/util/copyobj.m Mon Dec 18 17:30:48 2017 -0800 @@ -169,6 +169,35 @@ %! set (hnew, "position", [scrn(3)/2, scrn(4)/2-pos(4)/2, pos(3:4)]); %! drawnow (); +%!demo +%! hobj = clf; +%! set (hobj, "name", "Original", "numbertitle", "off"); +%! x = 0:0.1:2*pi; +%! y1 = sin (x); +%! y2 = exp (x - 1); +%! ax = plotyy (x,y1, x-1,y2, @plot, @semilogy); +%! xlabel ("X"); +%! ylabel (ax(1), "Axis 1"); +%! ylabel (ax(2), "Axis 2"); +%! lcolor = get (gca, "ColorOrder")(1,:); +%! rcolor = get (gca, "ColorOrder")(2,:); +%! text (0.5, 0.5, "Left Axis", ... +%! "color", lcolor, "horizontalalignment", "center", "parent", ax(1)); +%! text (4.5, 80, "Right Axis", ... +%! "color", rcolor, "horizontalalignment", "center", "parent", ax(2)); +%! title ({"plotyy() example"; "left axis uses @plot, right axis uses @semilogy"}); +%! drawnow (); +%! pos = get (hobj, "position"); +%! scrn = get (0, "screensize"); +%! set (hobj, "position", [scrn(3)/2-pos(3)-10, scrn(4)/2-pos(4)/2, pos(3:4)]); +%! drawnow (); +%! hnew = copyobj (hobj); +%! drawnow (); +%! set (hnew, "name", "Copyobj"); +%! drawnow (); +%! set (hnew, "position", [scrn(3)/2, scrn(4)/2-pos(4)/2, pos(3:4)]); +%! drawnow (); + %!testif HAVE_MAGICK; any (strcmp ("gnuplot", available_graphics_toolkits ())) %! toolkit = graphics_toolkit (); %! graphics_toolkit ("gnuplot");