# Plotting a 3d graph and a 2d contour map on the same plot

Is it possible to plot a 3d graph and a 2d contour map on the same plot?

Thank you!

edit retag close merge delete

A concrete example of what you aim to do would be a great help...

( 2023-10-04 21:50:47 +0200 )edit

Sort by ยป oldest newest most voted

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)

more

Thanks for the code and the link!

( 2023-10-05 05:51:15 +0200 )edit