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)