From: Hans F. <H.F...@so...> - 2004-09-21 06:56:28
|
Dear all, I am trying to use gcurve to continuously display the last N points of a scalar function. More concrete: a simulation goes through a number of iterations and for each iteration, I'd like to plot one scalar value. I want to display the last N points using gcurve. Since I didn't see a way of deleting individual points from gcurve, I have written the little class (appended below) which does nearly what I want. What it doesn't do is to auto-scale the graph so that the last N points are displayed in optimal resolution. I am happy to compute the required min and max values for the y-axis myself but don't know how to pass it to vpython in the correct way. Can anybody help me? Or is this plotting of last N-points achievable much easier using another approach? Thank you, Hans import Numeric import visual.graph class PlotLastPoints: """plots the last N points of data that is provided subsequently. The first N-points are drawn using the usual vpython-gcurve(pos=[x,y]) method. After that, the first point is overwritten with the N+1 entry, the 2nd point is replaced by the N+2 value etc. This is intended for a simulation where we have iterations on the x-axis, so the actual value there doesn't really matter. Bug: By not using gcurve's default mechanism for adding points, visual doesn't autoscale the graphs. """ def __init__(self,N): self.N = N self.data=Numeric.zeros((N,),'d') self.last = 0 self.disp=visual.graph.gdisplay(width=600,height=200) self.plot = visual.graph.gcurve() self.full = False #have we more or exactly N points in self.data ? def update(self, E ): if self.full == False and (self.last == self.N): self.full = True if self.full: self.last = self.last % self.N self.data[self.last]=E self.plot.gcurve.x=Numeric.arange(self.N)[:] self.plot.gcurve.y=self.data[:] else: self.plot.plot(pos=[self.last,E]) self.data[self.last]=E self.last +=1 if __name__=="__main__": import math,time plot = PlotLastPoints(50) for i in range(2000): plot.update( math.sin(i/50.0)) time.sleep(0.02) |
From: Gary <pa...@in...> - 2004-09-21 13:37:51
|
Hans Fangohr wrote: > Dear all, I am trying to use gcurve to continuously display the last N > points of a scalar function. More concrete: a simulation goes through > a number of iterations and for each iteration, I'd like to plot one > scalar value. I want to display the last N points using gcurve. I'm not exactly sure what you are trying to achieve, but I have something that seems similar. I wanted a stripchart... somthing that displays the latest data, while the older data falls off of the other end. Pmw.Blt has a stripchart. So I married Pmw.Blt and Vpython. An early demo is here: http://enigma.rider.edu/~gpajer/python.htm (IT is warning us that this server may disappear soon ... so don't delay!) since then I've spruced it up a bit, but this example displays various little features. The code is a bit hard to read ... sorry about that. It is also possible to make a stripchart using matplotlib (matplotlib.sf.net) . It's much slower (see below). Blt seems no longer supported or developed, but it works. A shame ... it has some nice features. For some reason, it is hard to install. I can attest that Pmw.Blt *does* work on Windows, OS X, and Linux. Windows instructions are on my weblink above. On OS X, it installs and runs readily using fink. Because of a bug in the configure script, Linux requires an environment variable ... can't recall it right now. I'll get it later if anyone wants it. [commercial break: nothing against matplotlib!!! I find that the combination of ipython/scipy/matplotlib/Vpython plus the non-pythonic Maxima makes a powerhouse of a scientific package. More functionality than Matlab or Mathematica at none of the price. And better support :) ] -gary |
From: <sb...@ma...> - 2004-10-04 19:10:15
|
I would like to install Vpython on my office desktop on which, unfortunately, I cannot be root. ( the system has got python2.2} Is that possible? Many thanks Luca |
From: Bruce S. <Bru...@nc...> - 2004-10-05 00:23:28
|
I'm not sure about other platforms, but at least on Windows Python itself offers a way to install without administrative privileges. I did this myself once. You might have to do this on a computer you control, because the VPython installer automatically will look for and find the existing python2.2. After installing the "rootless" Python, try installing VPython, and you'll be asked where to find Python (since there won't be anything in the registry to tell it where Python is). Tell the VPython installer to install into the Python directory. Now all you have to do is carry the whole Python directory to your office machine and put it in your own space. Bruce Sherwood sb...@ma... wrote: > I would like to install Vpython on my office desktop on which, > unfortunately, I cannot be root. ( the system has got python2.2} > > Is that possible? > > Many thanks > > Luca |
From: Hans F. <H.F...@so...> - 2004-09-21 07:02:18
Attachments:
lastpoints.py
|
Apologies: I noticed that the my mail client seems to have broken the indentation in my previous email. This time I will attach the program. Apologies for the 2nd email. Regards, Hans On Tue, 21 Sep 2004, Hans Fangohr wrote: > Dear all, I am trying to use gcurve to continuously display the last N > points of a scalar function. More concrete: a simulation goes through > a number of iterations and for each iteration, I'd like to plot one > scalar value. I want to display the last N points using gcurve. > > Since I didn't see a way of deleting individual points from gcurve, I > have written the little class (appended below) which does nearly what > I want. What it doesn't do is to auto-scale the graph so that the last > N points are displayed in optimal resolution. I am happy to compute > the required min and max values for the y-axis myself but don't know > how to pass it to vpython in the correct way. > > Can anybody help me? Or is this plotting of last N-points achievable > much easier using another approach? > > Thank you, > > Hans > > > Please find program attached. |