Ask Your Question
3

Plotting successive 3D plots in a for loop (only the last one can be plotted!)

asked 2011-01-26 12:11:14 +0100

myildi gravatar image

updated 2011-01-26 12:13:33 +0100

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. Murat

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2011-01-26 13:40:28 +0100

niles gravatar image

updated 2011-01-27 10:30:05 +0100

This 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.

edit flag offensive delete link more

Comments

Thank 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.

myildi gravatar imagemyildi ( 2011-01-26 17:33:10 +0100 )edit

Yes, the graphics in sage are still in a pretty rough state, unfortunately.

niles gravatar imageniles ( 2011-01-27 10:30:39 +0100 )edit

Thank you very much again Niles!

I can plot from the terminal in this case. It is better than nothing ;-)

Best regards,

Murat

myildi gravatar imagemyildi ( 2011-01-27 13:07:36 +0100 )edit

Glad to help :) If you want, you can click the small check mark to "accept" my answer :)

niles gravatar imageniles ( 2011-01-27 13:22:12 +0100 )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

Stats

Asked: 2011-01-26 12:11:14 +0100

Seen: 1,089 times

Last updated: Jan 27 '11