VPython7 issue with Jupyter Notebook

501 views
Skip to first unread message

Michael Bentley

unread,
Oct 25, 2017, 6:29:36 AM10/25/17
to VPython-users
Hello

I am teaching an undergrad course where I extensively use VPython. Last year I used VPython 6 (Classic) in Python 2.7 with VIDLE and have now upgraded to using VPython 7 with Python 3.6. I want to use the Jupyter notebook to teach the course, since it has many advantages, but I have hit a problem I cant solve. 

When running VPython7 from within Jupyter, the graphics window is displayed properly when the program/cell is executed. However, if I try to run the program/cell (containing VPython code) again, the graphics window does not appear. I believe this is because the graphics environment is still running from the last execute (I have seen posts about this). I presume this is so that the user can still interact with the window, change views etc. The only way to stop this completely, to enable a re-run of the code, seems to be to kill the kernel and clear the output. But then, if using multiple cells, all cells would need to be re-run since the kernel has been cleared. This seems to defeat the point of the notebook, and this is very painful way develop some code using VPython.

Is there a way to stop/kill/end the VPython display cleanly, without clearing the kernel? I had thought that VPython7 was designed with Jupyter in mind, so I have probably missed something crucial here. 

Thanks

Mike

Aaron Titus

unread,
Oct 25, 2017, 8:17:35 AM10/25/17
to vpytho...@googlegroups.com
I’ve used VPython in Jupyter for a while, and I’ve found that creating a scene explicitly by calling canvas() before creating 3D objects is essential. Try using:

scene=canvas(title="My 3D scene”)
sphere()

This also allows me to embed multiple scenes in a single notebook. Each scene will appear below the cell where it is created. Also, when I edit the cell and re-execute the cell, the scene will be updated properly and will not disappear.

I occasionally have to restart the kernel. But I think calling canvas() solves most of the problems you described.

Aaron

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Bentley

unread,
Oct 25, 2017, 12:52:46 PM10/25/17
to VPython-users
Aaron - thank you. This has indeed solved some of the problems, but not all.

I also heavily use the gcurve() graphing function. For example, I might use the following to draw two graphs:

win1 = graph(xtitle="Distance [m]", ytitle="Height [m]")
win2 = graph(xtitle="Distance [m]", ytitle="Height [m]")
c1 = gcurve(graph=win1, color=color.green)
c2 = gcurve(graph=win2, color=color.red)

I dont see how I can use the scene() function here, so I end up the same problem once both graphs are drawn... 

Any further help you could give would be much appreciated. 

Thanks
Mike


Michael Bentley

unread,
Oct 25, 2017, 5:07:07 PM10/25/17
to VPython-users
Apologies - I have it now:

scene1 = canvas()
scene2 = canvas()
g1 = graph(canvas=scene1, xtitle="Distance [m]", ytitle="Height [m]")
g2 = graph(canvas=scene2, xtitle="Distance [m]", ytitle="Height [m]")
c1 = gcurve(graph=g1, color=color.green)
c2 = gcurve(graph=g2, color=color.red)

Thank you for the help

Mike

Aaron Titus

unread,
Oct 25, 2017, 5:26:00 PM10/25/17
to vpytho...@googlegroups.com
Super. Thanks for letting us know.

Aaron

Bruce Sherwood

unread,
Oct 25, 2017, 8:17:38 PM10/25/17
to VPython-users
Two comments:

Although it's not caught as an error in VPython 7, "canvas" is not an attribute of a graph. It should give an error (it does in GlowScript VPython) but because there isn't an explicit check for it it's treated as a "user attribute" (that is, an attribute that VPython doesn't do anything with).

Also, note that if you aren't actually using the Jupyter notebook as a presentation and/or documentation device, but you're just writing and testing VPython programs, you might prefer to launch programs from IDLE or other IDE. See the first page of vpython.org for details.

Bruce

Todd Zimmerman

unread,
Oct 31, 2017, 10:29:24 AM10/31/17
to VPython-users
Thanks Aaron, I've been having this problem too and was just about to post to this forum.

-Todd
Reply all
Reply to author
Forward
0 new messages