Ask Your Question
3

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

asked 14 years ago

myildi gravatar image

updated 14 years ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 14 years ago

niles gravatar image

updated 14 years ago

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.

Preview: (hide)
link

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 ( 14 years ago )

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

niles gravatar imageniles ( 14 years ago )

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 ( 14 years ago )

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

niles gravatar imageniles ( 14 years ago )

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: 14 years ago

Seen: 1,188 times

Last updated: Jan 27 '11