changeset 8258:2b408bbd8904

Add error bar series
author David Bateman <dbateman@free.fr>
date Wed, 22 Oct 2008 11:21:28 +0100
parents 79c874fe5100
children dad9a322c639
files doc/ChangeLog doc/interpreter/plot.txi scripts/ChangeLog scripts/plot/__errplot__.m scripts/plot/errorbar.m
diffstat 5 files changed, 202 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Wed Oct 22 04:30:17 2008 +0100
+++ b/doc/ChangeLog	Wed Oct 22 11:21:28 2008 +0100
@@ -1,5 +1,10 @@
 2008-10-22  David Bateman  <dbateman@free.fr>
 
+	* interprter/plot.txi: Add documentation for error bar series.
+
+	* interprter/plot.txi: Update documentation for line series, Add 
+	documetation for scatter groups, stem series and surface groups.
+
 	* texinfo.tex: Import new upstream version.
 	* interpreter/Makefile.in (EXAMPLE_FILES_NODIR): Update for new OOP
 	class example location.
--- a/doc/interpreter/plot.txi	Wed Oct 22 04:30:17 2008 +0100
+++ b/doc/interpreter/plot.txi	Wed Oct 22 11:21:28 2008 +0100
@@ -1709,7 +1709,79 @@
 @cindex series objects
 @cindex error bar series
 
-TO BE WRITTEN
+Error bar series are created by the @code{errorbar} function. Each 
+@code{hgrroup} element contains two line objects represnting the data and
+the errorbars separately. The properties of the error bar series are
+
+@table @code
+@item color
+The RGB color or color name of the line objects of the error bars. @xref{Colors}.
+
+@item linewidth
+@itemx linestyle
+The line width and style of the line objects of the error bars. @xref{Line Styles}.
+
+@item marker
+@itemx markeredgecolor
+@itemx markerfacecolor
+@itemx markersize
+The line and fill color of the markers on the error bars. @xref{Colors}.
+
+@item xdata
+@itemx ydata
+@itemx ldata
+@itemx udata
+@itemx xldata
+@itemx xudata
+The original x, y, l, u, xl, xu data of the error bars.
+
+@item xdatasource
+@itemx ydatasource
+@itemx ldatasource
+@itemx udatasource
+@itemx xldatasource
+@itemx xudatasource
+Data source variables.
+@end table
+
+@node Surface group
+@subsubsection Surface group
+@cindex group objects
+@cindex surface group
+
+Surface group objects are created by the @code{surf} or @code{mesh}
+functions, but are equally one of the handles returned by the @code{surfc}
+or @code{meshc} functions. The surface group is of the type @code{surface}.
+
+The properties of the surface group are
+
+@table @code
+@item edgecolor
+@item facecolor
+The RGB color or color name of the edges or faces of the surface. @xref{Colors}.
+
+@item linewidth
+@itemx linestyle
+The line width and style of the lines on the surface. @xref{Line Styles}.
+
+@item marker
+@itemx markeredgecolor
+@itemx markerfacecolor
+@itemx markersize
+The line and fill color of the markers on the surface. @xref{Colors}.
+
+@item xdata
+@itemx ydata
+@itemx zdata
+@item cdata
+The original x, y, z and c data.
+
+@item xdatasource
+@itemx ydatasource
+@itemx zdatasource
+@itemx cdatasource
+Data source variables.
+@end table
 
 @node Line series
 @subsubsection Line series
--- a/scripts/ChangeLog	Wed Oct 22 04:30:17 2008 +0100
+++ b/scripts/ChangeLog	Wed Oct 22 11:21:28 2008 +0100
@@ -1,5 +1,8 @@
 2008-10-22  David Bateman  <dbateman@free.fr>
 
+	* plot/__errplot__.m: Add errorbar series objects.
+	* plot/errbar.m: Add some demos.
+	
 	* plot/__add_line_series__.m: Remove
 	* plot/Makefile.in (SOURCES): Remove it here too.
 	* plot/__add_datasource__.m: Allow for more than one character in
--- a/scripts/plot/__errplot__.m	Wed Oct 22 04:30:17 2008 +0100
+++ b/scripts/plot/__errplot__.m	Wed Oct 22 11:21:28 2008 +0100
@@ -29,67 +29,150 @@
     print_usage ();
   endif
 
-  [fmt, key] = __pltopt__ ("__errplot__", fstr);
+  fstr
+  [fmt, key] = __pltopt__ ("__errplot__", fstr)
 
   [len, nplots] = size (a1);
+  h = [];
 
   for i = 1:nplots
     ## Set the plot type based on linestyle.
-    if (fmt.linestyle == "~")
+
+    if (strcmp (fmt.linestyle, "~"))
       ifmt = "yerr";
-    elseif (fmt.linestyle == ">")
+    elseif (strcmp (fmt.linestyle, ">"))
       ifmt = "xerr";
-    elseif (fmt.linestyle == "~>")
+    elseif (strcmp (fmt.linestyle, "~>"))
       ifmt = "xyerr";
-    elseif (fmt.linestyle == "#")
+    elseif (strcmp (fmt.linestyle, "#"))
       ifmt = "box";
-    elseif (fmt.linestyle == "#~")
+    elseif (strcmp (fmt.linestyle, "#~"))
       ifmt = "boxy";
-    elseif (fmt.linestyle == "#~>")
+    elseif (strcmp (fmt.linestyle, "#~>"))
       ifmt = "boxxy";
     else
       print_usage ();
     endif
 
-    h = __line__ (p);
+    hg = hggroup ("parent", p);
+    h = [h; hg];
+    args = __add_datasource__ ("__errplot__", hg, 
+			       {"x", "y", "l", "u", "xl", "xu"});
+
+    if (isempty (fmt.color))
+      hl = __line__ (hg, "color", __next_line_color__ ());
+    else
+      hl = __line__ (hg, "color", fmt.color);
+    endif
+
+    ## FIXME
+    ## Note the below adds the errorbar data directly as ldata, etc 
+    ## properties of the line objects, as gnuplot can handle this.
+    ## Matlab has the errorbar part of the plot as a special line object
+    ## with embedded NaNs that draws the three segments of the bar
+    ## separately. Should we duplicate Matlab's behavior and stop using the
+    ## ldata, etc properties of the line objects that are Octace specific?
 
     switch (nargin - 2)
+      case 1
+	error ("error plot requires 2, 3, 4 or 6 columns");
       case 2
-	set (h, "xdata", (1:len)');
-	set (h, "ydata", a1(:,i));
-	set (h, "ldata", a2(:,i));
-	set (h, "udata", a2(:,i));
+	set (hl, "xdata", (1:len)');
+	set (hl, "ydata", a1(:,i));
+	set (hl, "ldata", a2(:,i));
+	set (hl, "udata", a2(:,i));
       case 3
-	set (h, "xdata", a1(:,i));
-	set (h, "ydata", a2(:,i));
-	set (h, "ldata", a3(:,i));
-	set (h, "udata", a3(:,i));
+	set (hl, "xdata", a1(:,i));
+	set (hl, "ydata", a2(:,i));
+	set (hl, "ldata", a3(:,i));
+	set (hl, "udata", a3(:,i));
       case 4
-	set (h, "xdata", a1(:,i));
-	set (h, "ydata", a2(:,i));
+	set (hl, "xdata", a1(:,i));
+	set (hl, "ydata", a2(:,i));
 
 	if (index (ifmt, "boxxy") || index (ifmt, "xyerr"))
-	  set (h, "xldata", a3(:,i));
-	  set (h, "xudata", a3(:,i));
-	  set (h, "ldata", a4(:,i));
-	  set (h, "udata", a4(:,i));
+	  set (hl, "xldata", a3(:,i));
+	  set (hl, "xudata", a3(:,i));
+	  set (hl, "ldata", a4(:,i));
+	  set (hl, "udata", a4(:,i));
 	elseif (index (ifmt, "xerr"))
-	  set (h, "xldata", a3(:,i));
-	  set (h, "xudata", a4(:,i));
+	  set (hl, "xldata", a3(:,i));
+	  set (hl, "xudata", a4(:,i));
 	else
-	  set (h, "ldata", a3(:,i));
-	  set (h, "udata", a4(:,i));
+	  set (hl, "ldata", a3(:,i));
+	  set (hl, "udata", a4(:,i));
 	endif
       case 5
 	error ("error plot requires 2, 3, 4 or 6 columns");
       case 6
-	set (h, "xdata", a1(:,i));
-	set (h, "ydata", a2(:,i));
-	set (h, "xldata", a3(:,i));
-	set (h, "xudata", a4(:,i));
-	set (h, "ldata", a5(:,i));
-	set (h, "udata", a6(:,i));
+	set (hl, "xdata", a1(:,i));
+	set (hl, "ydata", a2(:,i));
+	set (hl, "xldata", a3(:,i));
+	set (hl, "xudata", a4(:,i));
+	set (hl, "ldata", a5(:,i));
+	set (hl, "udata", a6(:,i));
     endswitch
+
+    addproperty ("color", hg, "linecolor", get (hl, "color"));
+    addproperty ("linewidth", hg, "linelinewidth", get (hl, "linewidth"));
+    addproperty ("linestyle", hg, "linelinestyle", get (hl, "linestyle"));
+    addproperty ("marker", hg, "linemarker", get (hl, "marker"));
+    addproperty ("markerfacecolor", hg, "linemarkerfacecolor", 
+		 get (hl, "markerfacecolor"));
+    addproperty ("markeredgecolor", hg, "linemarkerfacecolor", 
+		 get (hl, "markeredgecolor"));
+    addproperty ("markersize", hg, "linemarkersize", 
+		 get (hl, "markersize"));
+
+    addlistener (hg, "color", @update_props);
+    addlistener (hg, "linewidth", @update_props); 
+    addlistener (hg, "linestyle", @update_props); 
+    addlistener (hg, "marker", @update_props); 
+    addlistener (hg, "markerfacecolor", @update_props); 
+    addlistener (hg, "markersize", @update_props);
+
+    addproperty ("xdata", hg, "data", get (hl, "xdata"));
+    addproperty ("ydata", hg, "data", get (hl, "ydata"));
+    addproperty ("ldata", hg, "data", get (hl, "ldata"));
+    addproperty ("udata", hg, "data", get (hl, "udata"));
+    addproperty ("xldata", hg, "data", get (hl, "xldata"));
+    addproperty ("xudata", hg, "data", get (hl, "xudata"));
+
+    addlistener (hg, "xdata", @update_data);
+    addlistener (hg, "ydata", @update_data);
+    addlistener (hg, "ldata", @update_data);
+    addlistener (hg, "udata", @update_data);
+    addlistener (hg, "xldata", @update_data);
+    addlistener (hg, "xudata", @update_data);
+
+    __line__ (hg, "xdata", get (hl, "xdata"), 
+	      "ydata", get (hl, "ydata"), 
+	      "color", get (hl, "color"),
+	      "linewidth", get (hl, "linewidth"),
+	      "linestyle", get (hl, "linestyle"), 
+	      "marker", "none", "parent", hg);
   endfor
 
 endfunction
+
+function update_props (h, d)
+  set (get (h, "children"), "color", get (h, "color"), 
+       "linewidth", get (h, "linewidth"), "linestyle", get (h, "linestyle"), 
+       "marker", get (h, "marker"), "markersize", get (h, "markersize"),
+       "markerfacecolor", get (h, "markerfacecolor"),
+       "markeredgecolor", get (h, "markeredgecolor"));
+endfunction
+
+function update_data (h, d)
+  x = get (h, "xdata");
+  y = get (h, "ydata");
+  l = get (h, "ldata");
+  u = get (h, "udata");
+  xl = get (h, "xldata");
+  xu = get (h, "xudata");
+
+  kids = get (h, "children");
+  set (kids(1), "xdata", x, "ydata", y);
+  set (kids(2), "xdata", x, "ydata", y, "ldata", l, "udata", u, 
+       "xldata", xl, "xudata", xu);
+endfunction
--- a/scripts/plot/errorbar.m	Wed Oct 22 04:30:17 2008 +0100
+++ b/scripts/plot/errorbar.m	Wed Oct 22 11:21:28 2008 +0100
@@ -127,3 +127,9 @@
   end_unwind_protect
 
 endfunction
+
+%!demo
+%! errorbar(0:10,rand(1,11),0.25*rand(1,11))
+
+%!demo
+%! errorbar(0:10,rand(1,11),rand(1,11), ">")