return z;
}
+/* Return a sorted list of unique entries in an array x */
+real[] set(real[] x) {
+ int i=1;
+ x = sort(x);
+ while (i < x.length){
+ if (x[i] == x[i-1])
+ x.delete(i);
+ else
+ i += 1;
+ }
+ return x;
+}
+
+/* Convert x,y,z arrays to a z matrix */
+real[][] extract_matrix(real[] xs, real[] ys, real[] zs) {
+ int i, j, k;
+ real[] x_set = set(xs);
+ real[] y_set = set(ys);
+ real[] z_col = array(y_set.length, 0);
+ real[][] z_matrix = array(n=x_set.length, z_col);
+ //assert zs.length == x_set.length*y_set.length;
+ for (i=0; i<x_set.length; ++i) {
+ for (j=0; j<y_set.length; ++j) {
+ for (k=0; k<x_set.length*y_set.length; ++k) {
+ if (xs[k] == x_set[i] && ys[k] == y_set[j]) {
+ z_matrix[i][j] = zs[k];
+ break;
+ }
+ }
+ }
+ }
+ return z_matrix;
+}
+
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) {
+ pen[] p=BWRainbow(), Label x_label=null,
+ Label y_label=null, Label palette_label=null,
+ real palette_offset=6pt, real palette_width=12pt) {
file fin = input(file).line();
real[][] a = fin.dimension(0,0);
/* drop blank lines used to separate Gnuplot blocks. */
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);
+ real[] xs = a[0];
+ real[] ys = a[1];
+ real[] zs = zfn(a[2]);
+ real[][] z = extract_matrix(xs, ys, zs);
+ pair initial = (xscale*min(xs), yscale*min(ys));
+ pair final = (xscale*max(xs), yscale*max(ys));
+ //bounds range = image(pic=pic, x=xscale*x, y=yscale*y, f=z, palette=p);
+ bounds range = image(pic=pic, z, initial, final, range=Automatic, palette=p);
+ // Add axes before palette or palette will end up in same box as the image
+ if (x_label != null)
+ xaxis(pic, x_label, BottomTop,LeftTicks,above=true);
+ if (y_label != null)
+ yaxis(pic, y_label, LeftRight,RightTicks,above=true);
+ transform graph_to_pic = pic.calculateTransform();
+ transform pic_to_graph = inverse(graph_to_pic);
+ pair p_SE_pic = graph_to_pic * (xscale*max(xs), yscale*min(ys));
+ pair p_initial_graph = pic_to_graph * (p_SE_pic + palette_offset*E);
+ pair p_NE_pic = graph_to_pic * (xscale*max(xs), yscale*max(ys));
+ pair p_final_graph = pic_to_graph * (p_NE_pic
+ + (palette_offset+palette_width)*E);
if (palette_label == null)
- palette(pic=pic, bounds=range, initial=initial, final=final, palette=p);
+ palette(pic, bounds=range, initial=p_initial_graph, final=p_final_graph,
+ axis=Right, palette=p);
else
- palette(pic=pic, L=palette_label, bounds=range, initial=initial,
- final=final, palette=p);
+ palette(pic, L=palette_label, bounds=range, initial=p_initial_graph,
+ final=p_final_graph, axis=Right, palette=p);
}
string units(string value, string units) {
size(15cm,10cm,IgnoreAspect);
-scale(Log, Linear);
+scale(Log, Linear, Log);
real xscale=1;
-real yscale=1;
+real yscale=1e9;
-graphMatrixFile("data", xscale=xscale, yscale=yscale, zfn=log10);
-
-xlimits(0.002,0.26383);
-ylimits(0.12,0.198077);
+graphMatrixFile("data", xscale=xscale, yscale=yscale,
+ x_label="$k_{uo}$ (s$^{-1}$)", y_label="$x_u$ (nm)",
+ palette_label="$D_\text{JS}$");
label(sLabel("Fit quality"), point(N),N);
-xaxis(sLabel("$k_{uo}$ (s$^{-1}$)"),BottomTop,LeftTicks);
-yaxis(sLabel("$x_u$ (nm)"),LeftRight,RightTicks);
-
-add(legend(),point(E),20E,UnFill);