Generalized wtk_graph functions to allow user-controlled x/y/z columns
authorW. Trevor King <wking@drexel.edu>
Thu, 29 Apr 2010 21:59:57 +0000 (17:59 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 29 Apr 2010 21:59:57 +0000 (17:59 -0400)
tex/src/figures/asy/wtk_graph.asy

index 87c3ab95f31d0954cc12357487099de6df8135bc..40dd9337ef4909214f3bc38ef06c674f424f0f09 100644 (file)
@@ -13,6 +13,7 @@ Label sLabel(string s, align align=NoAlign, int extra_spaces=0) {
 }
 
 void graphFile(picture pic=currentpicture, string file="datafile",
+              int xcol=0, int ycol=1,
                real xscale=1, real yscale=1, pen p=red,
                path mpath=scale(0.8mm)*unitcircle,
               markroutine markroutine=marknodes,
@@ -23,8 +24,8 @@ void graphFile(picture pic=currentpicture, string file="datafile",
   file fin=input(file).line();
   real[][] a=fin.dimension(0,0);
   a=transpose(a);
-  real[] x=a[0];
-  real[] y=a[1];
+  real[] x=a[xcol];
+  real[] y=a[ycol];
   if (dots == true) {
     pline = invisible;
     mk = marker(mpath, markroutine, p);
@@ -75,6 +76,7 @@ real[][] extract_matrix(real[] xs, real[] ys, real[] zs) {
 }
 
 void graphMatrixFile(picture pic=currentpicture, string file="datafile",
+                    int xcol=0, int ycol=1, int zcol=2,
                      real xscale=1, real yscale=1,
                     real[] zfn(real[] z)=identity_zfn,
                     pen[] p=BWRainbow(), Label x_label=null,
@@ -87,9 +89,9 @@ void graphMatrixFile(picture pic=currentpicture, string file="datafile",
     if (a[i].length < 3)
       a.delete(i);
   a = transpose(a);
-  real[] xs = a[0];
-  real[] ys = a[1];
-  real[] zs = zfn(a[2]);
+  real[] xs = a[xcol];
+  real[] ys = a[ycol];
+  real[] zs = zfn(a[zcol]);
   real[][] z = extract_matrix(xs, ys, zs);
   pair initial = (xscale*min(xs), yscale*min(ys));
   pair final = (xscale*max(xs), yscale*max(ys));