Mercurial > octave
changeset 33568:54d87fbbb421 stable
legend.m: Avoid setting more colors than coordinates for patch objects (bug #65632).
* scripts/plot/appearance/legend.m (create_item): Take median color of patch or
surface objects for legend. Add demo with legend entry for patch object.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Fri, 10 May 2024 14:44:16 +0200 |
parents | 0698a2a8ed23 |
children | aa773ddbe25b |
files | scripts/plot/appearance/legend.m |
diffstat | 1 files changed, 29 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/appearance/legend.m Fri May 10 17:54:20 2024 -0400 +++ b/scripts/plot/appearance/legend.m Fri May 10 14:44:16 2024 +0200 @@ -1072,7 +1072,7 @@ persistent lprops = {"color", "linestyle", "linewidth"}; persistent mprops = {"color", "marker", "markeredgecolor", ... "markerfacecolor", "markersize"}; - persistent pprops = {"edgecolor", "facecolor", "cdata", ... + persistent pprops = {"edgecolor", "facecolor", ... "linestyle", "linewidth", ... "marker", "markeredgecolor", ... "markerfacecolor", "markersize"}; @@ -1125,11 +1125,16 @@ case {"patch", "surface"} vals = get (hplt, pprops); + cdata = get (hplt, "cdata"); - hicon = __go_patch__ (hl, [pprops; vals]{:}); + hicon = __go_patch__ (hl, [pprops; vals]{:}, ... + "cdata", median (median (cdata, 1), 2)); ## Listeners safe_property_link (hplt(1), hicon, pprops); + addlistener (hplt, "cdata", ... + @(h, ~) set (hicon, "cdata", ... + median (median (get (h, "cdata"), 1), 2))); setappdata (hicon, "__creator__", typ); @@ -1171,7 +1176,9 @@ ## Main patch vals = get (hplt(1), pprops); - hicon = __go_patch__ (hl, [pprops; vals]{:}, ... + cdata = get (hplt(1), "cdata"); + hicon = __go_patch__ (hl, "cdata", cdata, ... + [pprops; vals]{:}, ... "pickableparts", "all", ... "buttondownfcn", ... {@execute_itemhit, hl, hplt, "icon"}); @@ -1181,15 +1188,17 @@ ## Additional patch for the inner contour vals = get (hplt(end), pprops); + cdata = get (hplt(end), "cdata"); htmp = __go_patch__ (hl, "handlevisibility", "off", ... - "xdata", 0, "ydata", 0, [pprops; vals]{:}, ... + "xdata", 0, "ydata", 0, "cdata", cdata, ... + [pprops; vals]{:}, ... "pickableparts", "all", ... "buttondownfcn", ... {@execute_itemhit, hl, hplt, "icon"}); ## Listeners - safe_property_link (hplt(1), hicon, pprops); - safe_property_link (hplt(end), htmp, pprops); + safe_property_link (hplt(1), hicon, [{"cdata"}, pprops]); + safe_property_link (hplt(end), htmp, [{"cdata"}, pprops]); addlistener (hicon, "ydata", ... @(h, ~) set (htmp, "ydata", get (h, "innerydata"))); addlistener (hicon, "xdata", ... @@ -1911,6 +1920,20 @@ %! title ("legend() works for surface objects too"); %!demo +%! clf; +%! [x,y,z] = meshgrid (-.2:0.02:.2, -.2:0.02:.2, -.2:0.02:.2); +%! val = (x.^2 + y.^2 + z.^2); +%! +%! h_axes = axes (); +%! view (3); +%! fv = isosurface (x, y, z, val, .039, z); +%! h_patch = patch (fv, "FaceColor", "flat", "EdgeColor", "none"); +%! view (3); +%! axis tight +%! axis equal +%! legend ({"colored patch"}); + +%!demo %! clf reset; # needed to undo colormap assignment in previous demo %! rand_2x3_data2 = [0.44804, 0.84368, 0.23012; 0.72311, 0.58335, 0.90531]; %! bar (rand_2x3_data2);