changeset 17540:b7aa1d726bcc

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.
author Rik <rik@octave.org>
date Wed, 02 Oct 2013 21:58:56 -0700
parents 485aeffc0c22
children 48dccea1cf44
files scripts/plot/legend.m
diffstat 1 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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");