Ask Your Question
1

How to combine 3d and 2d plots?

asked 2019-05-13 14:52:54 -0500

Hi, I am trying to include 2d plots of a 3d functions in specific points, fx. if i have a plottet function z=y*z and then i want to plot a function over when y=1 or 2 or 3 and so on. or when x=1 or 2 or 3 and so on.

I am dealing with this assignment:

sage: x,y,z = var('x,y,z')
sage: f = x^2+sqrt(y)

Then i can prepare that one for a 3d plot

sage: P = f.plot3d((x,-5,5),(y,-5,5),color="red",opacity=0.7)

Then i read something somewhere that you can put the cuts in the 3dplot by

sage: plot3d(z=0, **kwds)

and they gave the EXAMPLE:

sage: sum([plot(z*sin(x), 0, 10).plot3d(z) for z in range(6)]) #long

So for my case i try

sage: S = sum([plot(x^2+sqrt(y), -5,5 for y in range(6)])
sage: K = P+S
sage: K.show(aspect_ratio=[1,1,1])

Because i don't know how to include the z axis in the example. So i get some lines but they are lying down on the x/y axis i tried changing the variable y with z but it doesnt change anything.

Please help me!

Kind regards Martin Mårtensson

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2019-05-14 17:11:57 -0500

slelievre gravatar image

If I understand correctly, the goal is to produce a 3d plot of a function of two variables, with some partial functions plotted on top of it.

The partial plots, or plots of the partial functions, are supposed to be inserted vertically at the relevant x or y values; in other words we want to visualize the intersections of the 3d plot with some vertical planes corresponding to a few particular values of x, and of y.

Here is one way this can be achieved.

Pick a function f of two variables to plot:

sage: f = lambda x, y: x^2 + sqrt(y)

Pick the x-range and the y-range:

sage: x_xx = (-3.1, 3.1)
sage: y_yy = (0, 6)

Define the 3d-plot with partial opacity.

sage: P = plot3d(f, x_xx, y_yy, color='red', alpha=0.25)

To plot partial functions of f, we will use:

sage: Px = lambda x: parametric_plot((lambda t: x, lambda t: t, lambda t: f(x, t)), y_yy)
sage: Py = lambda y: parametric_plot((lambda t: t, lambda t: y, lambda t: f(t, y)), x_xx)

Define a new graphics object G that initially is P and add the desired partial plots to it:

sage: G = P
sage: for x in (-3 .. 3):
....:     G += Px(x)
sage: for y in (0 .. 6):
....:     G += Py(y)

View the result (choices for the viewer include 'jmol', 'tachyon', 'threejs'):

sage: G.show(viewer='threejs')
edit flag offensive delete link more

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: 2019-05-13 14:52:54 -0500

Seen: 49 times

Last updated: May 14