ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 15 Apr 2018 16:46:15 -0500How to plot implicit3d plot with level sets in SageMath?https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/I want to plot a quadratic form with its level sets in SageMath. How to do that?
plot = Graphics()
plot+=plot3d(1/4*x^2+1/9*y^2,(x,-2,2),(y,-2,2))
for h in [0..5]:
plot+=contour_plot(f,(x,-4,4),(y,-4,4), fill=false, labels=true, contours=10,colorbar=true,cmap=matplotlib.cm.gist_rainbow).show(aspect_ratio=1)
show(plot)
How to achieve this?Tue, 10 Apr 2018 13:11:52 -0500https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/Comment by Emmanuel Charpentier for <p>I want to plot a quadratic form with its level sets in SageMath. How to do that?</p>
<pre><code>plot = Graphics()
plot+=plot3d(1/4*x^2+1/9*y^2,(x,-2,2),(y,-2,2))
for h in [0..5]:
plot+=contour_plot(f,(x,-4,4),(y,-4,4), fill=false, labels=true, contours=10,colorbar=true,cmap=matplotlib.cm.gist_rainbow).show(aspect_ratio=1)
show(plot)
</code></pre>
<p>How to achieve this?</p>
https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?comment=41995#post-id-41995Your question has several problems :
* you do not define $f$
* you do not use $h$
* you try to "add" a set of 2D plots to a 3D plot, without any specification of how to do this "addition".
Could you refine (rethink ?) your question ?Thu, 12 Apr 2018 14:19:01 -0500https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?comment=41995#post-id-41995Comment by j.c. for <p>I want to plot a quadratic form with its level sets in SageMath. How to do that?</p>
<pre><code>plot = Graphics()
plot+=plot3d(1/4*x^2+1/9*y^2,(x,-2,2),(y,-2,2))
for h in [0..5]:
plot+=contour_plot(f,(x,-4,4),(y,-4,4), fill=false, labels=true, contours=10,colorbar=true,cmap=matplotlib.cm.gist_rainbow).show(aspect_ratio=1)
show(plot)
</code></pre>
<p>How to achieve this?</p>
https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?comment=41984#post-id-41984I agree that it is not clear what level sets you're seeking to plot. However, the answers to these questions could be helpful https://ask.sagemath.org/question/9199/levelcontour-curves-in-3d/ https://ask.sagemath.org/question/8964/how-to-color-a-3d-plot-by-z-level/Wed, 11 Apr 2018 04:55:10 -0500https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?comment=41984#post-id-41984Comment by slelievre for <p>I want to plot a quadratic form with its level sets in SageMath. How to do that?</p>
<pre><code>plot = Graphics()
plot+=plot3d(1/4*x^2+1/9*y^2,(x,-2,2),(y,-2,2))
for h in [0..5]:
plot+=contour_plot(f,(x,-4,4),(y,-4,4), fill=false, labels=true, contours=10,colorbar=true,cmap=matplotlib.cm.gist_rainbow).show(aspect_ratio=1)
show(plot)
</code></pre>
<p>How to achieve this?</p>
https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?comment=41982#post-id-41982Please provide your definition of `f`. Ideally, one should be able to copy and paste
the code you provide in a fresh Sage session, to see what your problem is.Wed, 11 Apr 2018 04:32:38 -0500https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?comment=41982#post-id-41982Comment by slelievre for <p>I want to plot a quadratic form with its level sets in SageMath. How to do that?</p>
<pre><code>plot = Graphics()
plot+=plot3d(1/4*x^2+1/9*y^2,(x,-2,2),(y,-2,2))
for h in [0..5]:
plot+=contour_plot(f,(x,-4,4),(y,-4,4), fill=false, labels=true, contours=10,colorbar=true,cmap=matplotlib.cm.gist_rainbow).show(aspect_ratio=1)
show(plot)
</code></pre>
<p>How to achieve this?</p>
https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?comment=41981#post-id-41981Welcome to Ask Sage! Thank you for your question!Wed, 11 Apr 2018 04:29:11 -0500https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?comment=41981#post-id-41981Comment by daviddglmath for <p>I want to plot a quadratic form with its level sets in SageMath. How to do that?</p>
<pre><code>plot = Graphics()
plot+=plot3d(1/4*x^2+1/9*y^2,(x,-2,2),(y,-2,2))
for h in [0..5]:
plot+=contour_plot(f,(x,-4,4),(y,-4,4), fill=false, labels=true, contours=10,colorbar=true,cmap=matplotlib.cm.gist_rainbow).show(aspect_ratio=1)
show(plot)
</code></pre>
<p>How to achieve this?</p>
https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?comment=41973#post-id-41973I could not upload any image since i dont have enough karma for that. SorryTue, 10 Apr 2018 13:12:25 -0500https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?comment=41973#post-id-41973Answer by slelievre for <p>I want to plot a quadratic form with its level sets in SageMath. How to do that?</p>
<pre><code>plot = Graphics()
plot+=plot3d(1/4*x^2+1/9*y^2,(x,-2,2),(y,-2,2))
for h in [0..5]:
plot+=contour_plot(f,(x,-4,4),(y,-4,4), fill=false, labels=true, contours=10,colorbar=true,cmap=matplotlib.cm.gist_rainbow).show(aspect_ratio=1)
show(plot)
</code></pre>
<p>How to achieve this?</p>
https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?answer=42031#post-id-42031Similar questions have been asked on Ask Sage before, and solutions or
workarounds were given that work in a general enough case.
Here specifically, the function we study happens to be a quadratic form:
f = lambda x, y: 1/4*x^2 + 1/9*y^2
In this simple special case, the level set of level `r^2`, defined by
[z == 1/4 * x^2 + 1/9 * y^2, z == r^2]
are ellipses, and can be parametrized as
x = lambda r: lambda t: 2 * r * cos(t)
y = lambda r: lambda t: 3 * r * sin(t)
z = lambda r: lambda t: r^2
and then, defining the x-, y-, z- ranges, min and max as
xab = xa, xb = -9, 9
yab = ya, yb = -13, 13
zab = za, zb = 0, 18
we can plot the function (with some transparency):
p = plot3d(f, xab, yab, zmin=0, zmax=18, opacity=0.5)
and superimpose the desired level sets:
tau = 2*RDF.pi()
for r in range(5):
p += parametric_plot3d((x(r), y(r), z(r)), (0, tau), color='red')
and finally visualize the combination, either with jmol or threejs:
p.show(zmin=za, zmax=zb, aspect_ratio=1, viewer='jmol')
p.show(zmin=za, zmax=zb, aspect_ratio=1, viewer='threejs')
For other choices of viewers, see the documentation, by doing one of the following:
p.show?
help(p.show)
browse_sage_doc(p.show)
Sun, 15 Apr 2018 16:46:15 -0500https://ask.sagemath.org/question/41972/how-to-plot-implicit3d-plot-with-level-sets-in-sagemath/?answer=42031#post-id-42031