Ask Your Question
0

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

asked 2023-10-04 17:26:02 +0200

Tati gravatar image

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

Thank you!

edit retag flag offensive close merge delete

Comments

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

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-10-04 21:50:47 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-10-05 02:43:33 +0200

JC gravatar image

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)
edit flag offensive delete link more

Comments

Thanks for the code and the link!

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-10-04 17:26:02 +0200

Seen: 132 times

Last updated: Oct 05 '23