Jupyter VPython 0.3.10 supports side-by-side graphics and graphs

346 views
Skip to first unread message

Bruce Sherwood

unread,
May 16, 2016, 1:56:05 AM5/16/16
to VPython-users
Execute "pip install vpython --upgrade" to get version 0.3.10 that supports the following capability in Jupyter VPython.

This program forces a canvas (the default canvas, named "scene") to the left in the window, and forces a graph (named "plotting") to the right in the window, so that the graph appears to the right of the 3D canvas. If the window is too narrow to place them side by side, the graph will appear below the canvas.

from vpython import *
scene.align = 'left'
plotting = graph(width=400, height=400, align='right')

scene.title = "Make window wide to place the two views side by side."
scene.width = 400
box()

g = gcurve()
g.plot(1,2)
g.plot(5,-3)

Poul Riis

unread,
May 17, 2016, 4:22:54 PM5/17/16
to VPython-users
It's nice but in my opinion it is strongly desirable to have the output in separate windows like in classic VPython. Is that possible with Jupyter?

BTW, I tried your example with a larger number of points (see code below). It worked but increasing the number of points (npts) from 800 to 2000 gave problems: my computer became slow - it took several seconds to scroll up and down between code and output and I'm not sure that the program ever finished the plotting. I would like to know if that only happens on my computer?
At one instance I got the following error message:
ERROR! Session/line number was not unique in database. History logging moved to new session 313
but the message did not show up again when rerunning the program without changing anything!?

Poul Riis



from vpython import *
scene.align = 'left'
plotting = graph(width=400, height=400,xmin=-5,xmax=5,ymin=-5,ymax=5, align='right',title='2D-graph')

scene.title = "Make window wide to place the two views side by side."
scene.width = 400
box(pos=vec(0,0,0),length=1,height=2,width=3,color=color.red,opacity=0.5)
def axes(Lax):
    arrow(pos=vec(-Lax/2,0,0),axis=vec(Lax,0,0),color=color.yellow,fixedwidth=True,shaftwidth=0.05)
    arrow(pos=vec(0,-Lax/2,0),axis=vec(0,Lax,0),color=color.green,fixedwidth=True,shaftwidth=0.05)
    arrow(pos=vec(0,0,-Lax/2),axis=vec(0,0,Lax),color=color.blue,fixedwidth=True,shaftwidth=0.05)
axes(4)
g = gdots(color=color.magenta)
npts=800
phig=(3-sqrt(5))*pi
for i in range(0,npts):
    r=5*sqrt(i/npts)
    x=r*cos(i*phig)
    y=r*sin(i*phig)
    g.plot(x,y)

Bruce Sherwood

unread,
May 17, 2016, 4:56:21 PM5/17/16
to VPython-users
I don't know how to create a second notebook window; maybe someone else does. I think maybe John Coady once did some kind of experiment with displaying outside the notebook.

I see the same lockup that you see with the larger number of points. I put a print statement after the loop, which showed that the program finished executing almost instantly. There seems to be something wrong with the way VPython uses the standard Flot graphing package. Just today I saw a case where plotting a large number of points was very slow in GlowScript VPython.

I too occasionally the ERROR message. I think it's associated with not having successfully "restarted the kernel".

Ying-Jer Kao

unread,
Oct 3, 2016, 8:48:21 AM10/3/16
to VPython-users
Is it possible to put two canvases side-by-side? It seems that each canvas will try to occupy a line regardless of the width of the canvas. 

Bruce Sherwood

unread,
Oct 3, 2016, 10:47:32 AM10/3/16
to VPython-users
I don't understand the question. It is true that with this particular code the window has to be at 1225 pixels wide, and I don't understand why the Jupyter notebook environment insists on putting lots of white space between the two canvases. When the same code runs in GlowScript Vpython, the window has to be only 850 pixels wide, and with a window 850 pixels wide there is no white space between the two canvases.

Craig Wiegert

unread,
Oct 3, 2016, 11:04:59 AM10/3/16
to vpytho...@googlegroups.com
Hi Ying-Jer,

I was running into the same problem with two canvases, but Bruce's
recently-released Jupyter VPython 1.0.9 fixed it for me. If you haven't
upgraded your install, try that version and see if it helps.

- Craig
> --
> 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
> <mailto:vpython-user...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--
----------------------------------------------------------------------
Craig Wiegert Office: 215 Physics Building
Undergraduate Physics Coordinator
Associate Professor Phone: 706-542-4023
Department of Physics & Astronomy Fax: 706-542-2492
University of Georgia Email: wie...@physast.uga.edu
Athens, GA 30602-2451 cwie...@uga.edu
Reply all
Reply to author
Forward
0 new messages