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.Thu, 27 Jan 2011 13:22:12 +0100Plotting successive 3D plots in a for loop (only the last one can be plotted!)https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/Hi,
I have another problem with plotting multiple 3D plots.
When I execute the following two cells in the notebook interface:
Cell 1: (Definition of function that generates parametrized plots)
def plotPerceFL1 (aalpha):
p1_11 = plot3d(Fp1_11(alpha=aalpha),(x,0,1),(y,0,1),color="red")
p1_12 = plot3d(Fp1_12(alpha=aalpha),(x,0,1),(y,0,1),color="gray")
return p1_11+p1_12
Cel 2: (Plotting successive plots for different values of aalpha)
for a in srange(-1,1,step=0.25):
grr=plotPerceFL1(a)
grr.show()
I can see the loop running (if I print a, for example) but nothing is plotted until the end of the loop, then only the last graphic is shown.
Is there any trick to force Sage to successively plotting all graphics (and, preferably, to keep them in the screen one below the other)?
Thanks in advance for your help.
MuratWed, 26 Jan 2011 12:11:14 +0100https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/Answer by niles for <p>Hi,
I have another problem with plotting multiple 3D plots.
When I execute the following two cells in the notebook interface:</p>
<p>Cell 1: (Definition of function that generates parametrized plots)</p>
<pre><code>def plotPerceFL1 (aalpha):
p1_11 = plot3d(Fp1_11(alpha=aalpha),(x,0,1),(y,0,1),color="red")
p1_12 = plot3d(Fp1_12(alpha=aalpha),(x,0,1),(y,0,1),color="gray")
return p1_11+p1_12
</code></pre>
<p>Cel 2: (Plotting successive plots for different values of aalpha)</p>
<pre><code>for a in srange(-1,1,step=0.25):
grr=plotPerceFL1(a)
grr.show()
</code></pre>
<p>I can see the loop running (if I print a, for example) but nothing is plotted until the end of the loop, then only the last graphic is shown.</p>
<p>Is there any trick to force Sage to successively plotting all graphics (and, preferably, to keep them in the screen one below the other)? </p>
<p>Thanks in advance for your help.
Murat</p>
https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/?answer=12014#post-id-12014This will work if you use the Tachyon viewer (I don't know why it doesn't work with the jMol viewer).
For example, the following results in 3 spheres which are different shades of red:
for a in [0,.3,.5]:
grr=sphere(color=Color(a,0,0))
grr.show(viewer='tachyon')
---
Note that if you run the loop from the `sage:` command prompt rather than the notebook, you can get separate jMol 3D plots -- separate viewer applet is opened for each plot. So this is a notebook bug I guess.Wed, 26 Jan 2011 13:40:28 +0100https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/?answer=12014#post-id-12014Comment by niles for <p>This will work if you use the Tachyon viewer (I don't know why it doesn't work with the jMol viewer).</p>
<p>For example, the following results in 3 spheres which are different shades of red:</p>
<pre><code>for a in [0,.3,.5]:
grr=sphere(color=Color(a,0,0))
grr.show(viewer='tachyon')
</code></pre>
<hr/>
<p>Note that if you run the loop from the <code>sage:</code> command prompt rather than the notebook, you can get separate jMol 3D plots -- separate viewer applet is opened for each plot. So this is a notebook bug I guess.</p>
https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/?comment=22232#post-id-22232Glad to help :) If you want, you can click the small check mark to "accept" my answer :) Thu, 27 Jan 2011 13:22:12 +0100https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/?comment=22232#post-id-22232Comment by myildi for <p>This will work if you use the Tachyon viewer (I don't know why it doesn't work with the jMol viewer).</p>
<p>For example, the following results in 3 spheres which are different shades of red:</p>
<pre><code>for a in [0,.3,.5]:
grr=sphere(color=Color(a,0,0))
grr.show(viewer='tachyon')
</code></pre>
<hr/>
<p>Note that if you run the loop from the <code>sage:</code> command prompt rather than the notebook, you can get separate jMol 3D plots -- separate viewer applet is opened for each plot. So this is a notebook bug I guess.</p>
https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/?comment=12018#post-id-12018Thank you very much again Niles!
I can plot from the terminal in this case. It is better than nothing ;-)
Best regards,
MuratThu, 27 Jan 2011 13:07:36 +0100https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/?comment=12018#post-id-12018Comment by myildi for <p>This will work if you use the Tachyon viewer (I don't know why it doesn't work with the jMol viewer).</p>
<p>For example, the following results in 3 spheres which are different shades of red:</p>
<pre><code>for a in [0,.3,.5]:
grr=sphere(color=Color(a,0,0))
grr.show(viewer='tachyon')
</code></pre>
<hr/>
<p>Note that if you run the loop from the <code>sage:</code> command prompt rather than the notebook, you can get separate jMol 3D plots -- separate viewer applet is opened for each plot. So this is a notebook bug I guess.</p>
https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/?comment=22240#post-id-22240Thank you very much Niles, it works indeed. Unfortunately one looses the interesting tools that come with the jMol viewer (like rotating the graphs to better grasp their shape). Everything is a trade-off in this world ;-) Best regards.Wed, 26 Jan 2011 17:33:10 +0100https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/?comment=22240#post-id-22240Comment by niles for <p>This will work if you use the Tachyon viewer (I don't know why it doesn't work with the jMol viewer).</p>
<p>For example, the following results in 3 spheres which are different shades of red:</p>
<pre><code>for a in [0,.3,.5]:
grr=sphere(color=Color(a,0,0))
grr.show(viewer='tachyon')
</code></pre>
<hr/>
<p>Note that if you run the loop from the <code>sage:</code> command prompt rather than the notebook, you can get separate jMol 3D plots -- separate viewer applet is opened for each plot. So this is a notebook bug I guess.</p>
https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/?comment=22235#post-id-22235Yes, the graphics in sage are still in a pretty rough state, unfortunately.Thu, 27 Jan 2011 10:30:39 +0100https://ask.sagemath.org/question/7873/plotting-successive-3d-plots-in-a-for-loop-only-the-last-one-can-be-plotted/?comment=22235#post-id-22235