1 | initial version |
You may want to take a look at this post. Another option :
var('x y z')
g(x,y,z) = 2+2*(1-x)^2*exp(-(x^2) - (y+1)^2) +2*abs(x/5 - x^3 - y^5)*exp(-x^2-y^2)+ 1*exp(-(x+1)^2 - y^2)
f = z==g
S = plot3d(g(x,y), (x,-2,2),(y,-2,2), mesh=0, color = "orange", opacity = 0.5, frame = False, projection = "orthographic")
levels=srange(2,7,0.5)
Contours = Graphics()
for zlevel in levels:
S+=implicit_plot3d(g(x,y,z)-zlevel, (x,-2,2),(y,-2,2),(z,zlevel - 0.02,zlevel + 0.02),thickness=1, color = "brown")
for zlevel in levels:
Contours+=implicit_plot3d(f(x,y,zlevel), (x,-2,2),(y,-2,2),(z,- 0.03,+0.03),thickness=3, color = "blue")
S +=Contours
S += arrow3d((0,0,0),(2,0,0), color = "black")
S += text3d("x", (2.2,0,0), color = "black")
S += arrow3d((0,0,0),(0,3,0), color = "black")
S += text3d("y", (0,3.2,0), color = "black")
S += arrow3d((0,0,0),(0,0,7), color = "black")
S += text3d("z", (0,0,7.2), color = "black")
S += plot3d(0, (x,-2,2),(y,-2,2), color = "blue", opacity=0.25)
show(S)