I have a confusing problem with Asymptote. I want to draw a contour plot and a surface plot side-by-side and try this code:
settings.outformat="pdf";
settings.render=8;
settings.prc=false;
import graph3;
import contour;
real f(pair z) {return (z.x^2+3*z.y^2)*exp(1-z.x^2-z.y^2);}
picture pic1;
size(pic1,175);
int n=10;
real[] c=new real[n];
for(int i=0; i < n; ++i) c[i]=3*i/n;
Label[] Labels=sequence(new Label(int i) {
return Label(c[i] != 0 ? (string) c[i] : "",Relative(unitrand()), (0,0),UnFill(1bp));
},c.length);
draw(pic1,Labels,contour(f,(-2,-2),(2,2),c),black+1+fontsize(6pt));
picture pic2;
currentprojection=orthographic(0.8,1,1);
defaultrender.merge=true;
size(pic2,175,120,IgnoreAspect);
size3(pic2,175);
draw(pic2,surface(f,(-2,-2),(2,2),Spline),lightgreen);
add(pic1.fit(),(0,0),W);
add(pic2.fit(),(5mm,0),E);
shipout("test");
I get only the left-hand contour plot! [The character "|" is added to show the right hand side of the image.]
BUT, if I remove the Labels argument from the contour plot, I get both pictures (with no labels, of course).
Why? And what do I do about it?
add
commands is changed: firstadd(pic2.fit(),(5mm,0),E);
, thenadd(pic1.fit(),(0,0),W);
. Nice function, btw.