# HG changeset patch # User Rik # Date 1380776336 25200 # Node ID b7aa1d726bcc03413d055b36d23a9cca0852b15d # Parent 485aeffc0c2227daa91fcc92ae5bc9418b3c033c legend.m: Add support for surface objects. * scripts/plot/legend.m: Use a colored patch set to the mid-point of caxis() to represent a surface in the legend. diff -r 485aeffc0c22 -r b7aa1d726bcc scripts/plot/legend.m --- a/scripts/plot/legend.m Wed Oct 02 21:35:59 2013 -0700 +++ b/scripts/plot/legend.m Wed Oct 02 21:58:56 2013 -0700 @@ -882,7 +882,18 @@ endif case "surface" - ## FIXME: Would be nice to do something here + facecolor = get (hplots(k), "facecolor"); + edgecolor = get (hplots(k), "edgecolor"); + cdata = sum (caxis ()) / 2; + if (! strcmp (facecolor, "none") || ! strcmp (edgecolor, "none")) + p1 = patch ("xdata", ([0, linelength, linelength, 0] + + xoffset + xk * xstep) / lpos(3), + "ydata", (lpos(4) - yoffset - + [yk-0.3, yk-0.3, yk+0.3, yk+0.3] .* ystep) / lpos(4), + "facecolor", facecolor, "edgecolor", edgecolor, + "cdata", cdata, "userdata", hplots(k)); + hobjects(end+1) = p1; + endif endswitch @@ -1554,8 +1565,15 @@ %!demo % bug 39697 %! clf; %! plot (1:10); -%! legend ("Legend Text"); -%! title ({"Multi-line", "titles", "are a", "problem"}); +%! legend ('Legend Text'); +%! title ({'Multi-line', 'titles', 'are a', 'problem'}); + +%!demo +%! clf; +%! colormap (cool (64)); +%! surf (peaks ()); +%! legend ('peaks()') +%! title ('legend() works for surface objects too'); %!test %! toolkit = graphics_toolkit ("gnuplot");