A 3D plot in Jupyter VPython

269 views
Skip to first unread message

Bruce Sherwood

unread,
Jul 30, 2016, 4:33:55 PM7/30/16
to VPython-users
The zip file of Jupyter VPython demos at vpython.org


contains a new program, Plot3D, that is equivalent to the GlowScript VPython version at


The code is nearly the same in the two environments except for using label instead of 3D text to label the axes (the 3D text object isn't available yet in Jupyter VPython). 

However, there is one non-trivial and interesting difference. The GlowScript version constructs the curved surface on a 50 by 50 mesh, but the Jupyter version has to use a coarser 25 by 25 mesh to get comparable plotting speed. The reason for this is basically that Python loops have quite a high overhead -- that is, an empty loop runs rather slowly. In contrast, JavaScript loops have very little overhead, and GlowScript VPython is transpiled to JavaScript.

One of the main uses of the Python numpy module is to vectorize calculations where possible, with homogeneous numerical arrays, to avoid the cost of Python loops over lists. Since this isn't a problem in JavaScript, GlowScript VPython calculations typically run quite fast without the need of numpy (which isn't available as such in the browser). 

When I first programmed Plot3D in GlowScript VPython I used several "double" loops, looping over x with an embedded loop over y, but I rewrote the critical loops in such a way as to be single rather than double loops, and that made a big difference in the pure Python environment, though even so I also had to reduce the number of mesh points by a factor of 4 (50 by 50 => 25 by 25).


Reply all
Reply to author
Forward
0 new messages