As a followup to the previous post, the graphics software Asymptote will be used to generate a data plot along with the model curve. Given the extra effort that is needed to create an honest data plot using Asymptote, it seems likely that it was not written with such in mind. On the other hand, it is quite useful for creating non-data figures that would benefit from mathematical parameterization. Some examples of this latter use is forthcoming.

To compare to the last gnuplot output, the same Kirby2 data set will be used for this plot. The following script will generate a plot of the data along with the model curve. Some of the code are commented, to assist with understanding the various steps in accomplishing this.

// kirby2.asy //------------------------------------------------------------- // description: //------------------------------------------------------------- // asymptote script to plot kirby2 data set // see Kirby2.txt for original data with description // // //------------------------------------------------------------- // asymptote script written by: //------------------------------------------------------------- // Richard Duncan, Ph.D. // Georgia Perimeter College // 2016 Feb 14 // // //------------------------------------------------------------- // postprocessing notes: //------------------------------------------------------------- // output is pdf // to convert pdf to jpg use this command: // convert -density 300 kirby2.pdf kirby2.jpg // supplied by imagemagick // // import graph; settings.outformat="pdf"; size(360,252,IgnoreAspect); //--------------------------------------------- // plot window characteristics: //--------------------------------------------- real xmin = 0.0, xmax = 380; real ymin = 0.0, ymax = 99; fixedscaling(pic=currentpicture, min=(xmin,ymin), max=(xmax,ymax), p=nullpen, warn=false); // point style for plotted data points: marker datcircle = marker(g=scale(1.0mm)*unitcircle, p=blue); //--------------------------------------------- // read in kirby2 data set: //--------------------------------------------- file kdat = input("kirby2.dat"); real[][] a = kdat.dimension(0,2); a = transpose(a); // NB: order in kirby2 is Y,X real[] y=a[0], x=a[1]; // column arrays of x,y // each datum gets plotted as an individual point: pair[] fx; // this will store the (x,y) data pairs int j = 0; // zero-based index for data pairs while(j < y.length) { fx[j] = (x[j],y[j]); ++j; } // Asymptote plots an interpolating line by default // use an invisible pen so that isn't drawn // all points are drawn using datcircle, defined above: draw(graph(fx), legend="data", p=invisible, marker=datcircle); //--------------------------------------------- // model function: //--------------------------------------------- // regression parameters fit-resolved elsewhere: real b1 = 1.67437; real b2 = -0.139266; real b3 = 0.00259603; real b4 = -0.00172429; real b5 = 2.16644e-05; // rational function with five regression parameters: real y_model(real x) { real y = (b1 + b2*x + b3*x**2)/(1 + b4*x + b5*x**2); return y; } // plot the model using a red solid curve: draw(graph(y_model, xmin, xmax), legend="model", p=red+1.5); //--------------------------------------------- // supplement plot with legend and coordinate axes: //--------------------------------------------- add(legend(xmargin=1mm, perline=1, p=invisible), 80N+20E); xaxis("$x$", axis=Bottom, ticks=LeftTicks(Step=50), arrow=EndArrow); yaxis("$y$", axis=Left, ticks=LeftTicks(Step=10), arrow=EndArrow); // add a bit of whitespace around plot for aesthetics: shipout(bbox(0.25cm));

The plot showing the data and the model curve generated with this Asymptote script is shown next:

Currently it seems that the only curve fitting functionality built into Asymptote is for line regressions, i.e., only a linear least squares function is available. It should be possible to produce code to perform a nonlinear regression, but that requires some lower level coding and is beyond the scope of this post.