3

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.]

enter image description here|

BUT, if I remove the Labels argument from the contour plot, I get both pictures (with no labels, of course).

enter image description here|

Why? And what do I do about it?

2
  • 1
    It's odd, but both pictures appears OK when the order of the add commands is changed: first add(pic2.fit(),(5mm,0),E);, then add(pic1.fit(),(0,0),W);. Nice function, btw.
    – g.kov
    Jan 14, 2016 at 15:49
  • This is a very strange phenomenon. I have no idea why it's not working. Jan 18, 2016 at 5:27

1 Answer 1

1

First, if your primary goal is just to get this particular picture to work right, I suggest you follow the solution of g.kov and switch the two add statements.

As far as actually figuring out what's wrong, I still don't know the answer, but I have the following piece of data to add to the picture: if you allow the two images to overlap, the 3d image is only shown when it lies on top of the 2d image previously added. Furthermore, the labels that start to the left of the 3d image's left edge are allowed to go on top of the 3d image, but labels that start to the right (specifically the 0.3 label) are hidden underneath it.

add(pic1.fit(),(0,0));
add(pic2.fit(),(5mm,0),E);

enter image description here

Reversing the order of the add statements, the entire 3d image is shown and the 0.3 label is permitted on top of it:

add(pic2.fit(),(5mm,0),E);
add(pic1.fit(),(0,0));

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .