Visual gdisplay (graph) with scrolling x axis roll

158 views
Skip to first unread message

jason....@pavegen.co.uk

unread,
Apr 11, 2016, 5:58:59 AM4/11/16
to VPython-users
Hi,

In the previous vpython I've implemented graphs using a normal display entity, with curves.  Then scrolled it simply by updating the curve.x class attribute.

I now want to move the code to the gcurve class.

However if I modify the gcurve.curve.x the graph axis break.

I want to submit a patch to fix this, but I can't get it to work properly.  Whatever I do, the x axis scale changes at a different rate to the plot and the vertical axis text scrolls out of the screen.

vpython 6.11.

I've added the following member function to the gcurve class:

def shiftleft(self, dx):
x = self.gcurve.x[dx:]
y = self.gcurve.y[dx:]

self.gcurve.set_x(x)
self.gcurve.set_y(y)
if len(x):
display = self.gdisplay
display.minmax[xaxis] = [min(x), max(x)]
display.zero[xaxis].x = display.minmax[xaxis][negaxis]
display.resize(x[-1], y[-1], forcex=True)
display.axisdisplay(xaxis,posaxis)




Then in the main loop we do something like this.

from visual import *
from visual.graph import *
import numpy as np

gd = gdisplay(x=300, y=0, width=600, height=600,
title='Entropy', xtitle='time', ytitle='N',
foreground=color.black, background=color.white,
#xmax=np.pi * 2, xmin=0,
ymax=1, ymin=-1,
)

fun=gcurve(color=color.black)

MAXX = (2.0*np.pi)

x = np.linspace(0, MAXX, 20)
dx = x[1] - x[0]
y = sin(x)

#Plot initial data
xy = zip(x, y)

#fun.plot(pos=xy)

print len(x), x[0], x[-1]
rate(20)
while True:

#Find the right
if len(fun.gcurve.x):
right = fun.gcurve.x[-1]
else:
right = 0

#Get next data
newx = right + dx
newy = sin(newx)

if newx > MAXX:
#Shift the trace
fun.shiftleft(1)

#print "newx", right, newx

fun.plot(pos=(newx, newy))
rate(20)




Bruce Sherwood

unread,
Apr 11, 2016, 6:16:25 PM4/11/16
to VPython-users
Apparently you've left something out of the description of what you've done, since the gdisplay function resize doesn't have a forcex attribute, hence when I try your program it dies with this:

Traceback (most recent call last):
  File "Untitled", line 41
    fun.shiftleft(1)
  File "C:\Python27\Lib\site-packages\visual_common\graph.py", line 733, in shiftleft
    d.resize(x[-1], y[-1], forcex=True)
TypeError: resize() got an unexpected keyword argument 'forcex'


Bruce Sherwood

unread,
Apr 11, 2016, 6:18:45 PM4/11/16
to VPython-users
And a minor point: It's probably not a good idea to use "display" as a variable name, since that's the name of the 3D graphics element.

jason....@pavegen.co.uk

unread,
Apr 18, 2016, 3:55:47 PM4/18/16
to VPython-users
Hi,

I tried very hard to use gdisplay for this purpose, but the internal state combined with the internal calculations kept messing up my attempts.

I've re-written a new version of gidsplay that allows much simpler scrolling, I hope using much tidier code.
It currently lacks all the features of gdisplay (e.g. log graphs) but these could be added though I don't have time to do this right now as the scrolling x axis is all I need and this is working perfectly.

Is it worth me submitting my code as a basis perhaps as the basis for a new, improved gdisplay module?

Regards,
Jason


Bruce Sherwood

unread,
Apr 18, 2016, 5:05:48 PM4/18/16
to VPython-users
I'm not sure what to say. As was announced several months ago, Classic VPython is not longer supported (see the first page of vpython.org). However, if you produce an improved gdisplay, people still using Classic VPython might be happy to replace the current graph.py file with yours, which you could post to the forum.

jason....@pavegen.co.uk

unread,
Apr 18, 2016, 7:08:12 PM4/18/16
to VPython-users
Hi Bruce,

I'm a big fan and constant user of Jupyter notebook and qtconsole (as I was IPython previously). Though they are very good for interactive worksheets or developing programs they are not much use for a stand-alone apps, at least not without a lot of work. I once wrote an ATE test harness using IPython, but making it interactive for users without Python knowledge was very difficult.

Does this mean that VPython is no longer intended for stand-alone applications?  I thought we were moving towards wx for this purpose, has that plan been abandoned?

Though glowscript is a cool feature, I can't really mandate that a given app runs in a web browser hosted on a public site at half the speed or that a user must install Jupyter to just run a program I've created.  Not all users that that Python savvy and most would rather complexities were hidden from them. (What they really want is a Py2EXE installable)


Bruce Sherwood

unread,
Apr 18, 2016, 7:23:07 PM4/18/16
to VPython-users
A reasonable question, though it wasn't trivial to build standalone executables with Classic VPython, and an .exe file doesn't help a Mac or Linux user. There are various nibbles at the issue in the Jupyter world. Consider for example this link, where you can execute Jupyter VPython programs without installing anything:


As for GlowScript, I don't know what is meant by "half the speed", as GlowScript VPython programs run at speeds comparable to or faster than Classic VPython programs, due to the fact that JavaScript is inherently faster than Python. Also, GlowScript VPython programs need not be hosted at glowscript.org: you can export them to your own web site. The real disadvantage of GlowScript VPython is that you don't have access to the rich world of Python modules.

I don't see much of a connection between wx and stand-alone applications. What wx offered was widgets.

If you have not already read the following document, please do so, as it lays out the reasons why Classic VPython has become unsustainable:

Reply all
Reply to author
Forward
0 new messages