Added untested graphMatrixFile to wtk_graph.asy
authorW. Trevor King <wking@drexel.edu>
Wed, 28 Apr 2010 12:02:18 +0000 (08:02 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 28 Apr 2010 12:02:18 +0000 (08:02 -0400)
tex/src/figures/asy/wtk_graph.asy

index 80fccb7d8ade00591156f1221e3d0965b4ee8999..1e8b172609d7d6711a8162aba45530791adca5c0 100644 (file)
@@ -1,4 +1,5 @@
 import graph;
+import palette;
 
 real fsize=10;
 
@@ -35,6 +36,34 @@ void graphFile(picture pic=currentpicture, string file="datafile",
   }
 }
 
+real[] identity_zfn(real[] z) {
+  return z;
+}
+
+void graphMatrixFile(picture pic=currentpicture, string file="datafile",
+                     real xscale=1, real yscale=1,
+                    real[] zfn(real[] z)=identity_zfn,
+                    pen[] p=BWRainbow(), Label palette_label=null) {
+  file fin = input(file).line();
+  real[][] a = fin.dimension(0,0);
+  /* drop blank lines used to separate Gnuplot blocks. */
+  for (int i=a.length-1; i >= 0; --i)
+    if (a[i].length < 3)
+      a.delete(i);
+  a = transpose(a);
+  real[] x = a[0];
+  real[] y = a[1];
+  real[] z = a[2]; //zfn(a[2]);
+  bounds range = image(pic=pic, x=xscale*x, y=yscale*y, f=z, palette=p);
+  pair initial = point(SE) + (0,6pt);
+  pair final = point(NE) + (0,6pt);
+  if (palette_label == null)
+    palette(pic=pic, bounds=range, initial=initial, final=final, palette=p);
+  else
+    palette(pic=pic, L=palette_label, bounds=range, initial=initial,
+           final=final, palette=p);
+}
+
 string units(string value, string units) {
   return "$"+value+"\mbox{ "+units+"}$";
 }