ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 15 May 2019 00:11:57 +0200How to combine 3d and 2d plots?https://ask.sagemath.org/question/46508/how-to-combine-3d-and-2d-plots/ 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Ã¥rtenssonMon, 13 May 2019 21:52:54 +0200https://ask.sagemath.org/question/46508/how-to-combine-3d-and-2d-plots/Answer by slelievre for <p>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. </p>
<p>I am dealing with this assignment:</p>
<pre><code>sage: x,y,z = var('x,y,z')
sage: f = x^2+sqrt(y)
</code></pre>
<p>Then i can prepare that one for a 3d plot</p>
<pre><code>sage: P = f.plot3d((x,-5,5),(y,-5,5),color="red",opacity=0.7)
</code></pre>
<p>Then i read something somewhere that you can put the cuts in the 3dplot by</p>
<pre><code>sage: plot3d(z=0, **kwds)
</code></pre>
<p>and they gave the EXAMPLE:</p>
<pre><code>sage: sum([plot(z*sin(x), 0, 10).plot3d(z) for z in range(6)]) #long
</code></pre>
<p>So for my case i try</p>
<pre><code>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])
</code></pre>
<p>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.</p>
<p>Please help me!</p>
<p>Kind regards
Martin MÃ¥rtensson</p>
https://ask.sagemath.org/question/46508/how-to-combine-3d-and-2d-plots/?answer=46524#post-id-46524If 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')Wed, 15 May 2019 00:11:57 +0200https://ask.sagemath.org/question/46508/how-to-combine-3d-and-2d-plots/?answer=46524#post-id-46524