Re: [Matplotlib-users] animation.FuncAnimation

2011-12-21 Thread Nils Wagner
On Tue, 20 Dec 2011 10:48:42 -0600
  Ryan May  wrote:
> On Tue, Dec 20, 2011 at 8:00 AM, Nils Wagner
>  wrote:
>> Hi all,
>>
>> How do I use animation.FuncAnimation to plot real-life
>> data from parsing a text file ?
> 
> Here's a version that does what I think you want:
> 
> import matplotlib.pyplot as plt
> import matplotlib.animation as animation
> import sys
> import time
> import re
> 
> x_data   = [] # x
> y_data   = [] # y
> 
> fig   = plt.figure()
> ax= fig.add_subplot(111)
> curve,= ax.plot([],[],lw=2)
> ax.set_xlim(0,5)
> ax.set_ylim(0,25)
> ax.grid()
> 
> def tail_f(file):
>  while True:
>where = file.tell()  # current file position, an 
>integer (may
> be a long integer).
>line = file.readline()
>if re.search('without errors',line): break
># Always yield the line so that we return back to the 
>event loop. If we
># need to go back and read again, we'll get a free 
>delay from the
># animation system.
>yield line
>if not line:
>  file.seek(where)   # seek(offset[, whence]) 
>->None.  Move to
> new file position.
> 
> 
> def run(line, curve, x, y):
>if re.search('x=',line):
>liste = line.split('=')
>x.append(liste[1].strip())
>if re.search('y=',line):
>liste = line.split('=')
>y.append(liste[1].strip())
> 
>curve.set_data(x,y)
>print x,y
>return curve
> 
> # The passed in frames can be a func that returns a 
>generator. This
> # generator keeps return "frame data"
> def data_source(fname=sys.argv[1]):
>return tail_f(open(fname))
> 
> # This init function initializes for drawing returns any 
>initialized
> # artists.
> def init():
>curve.set_data([],[])
>return curve
> 
> line_ani = animation.FuncAnimation(fig, run, 
>data_source, init_func=init,
>fargs=(curve,x_data,y_data), interval=100)
> 
> plt.show()
> 
> 
> Ben was also right in that you could subclass 
>FuncAnimation and
> override/extend methods. This would have the benefit of 
>giving more
> control over the handling of seek(). (Something else for 
>my todo
> list...)
> 
> Ryan
> 
> -- 
> Ryan May
> Graduate Research Assistant
> School of Meteorology
> University of Oklahoma


Hi Ryan,

is it possible to autoscale the axes whenever it is needed 
by a new chunk of data ?

Nils

--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Griddata failling; how to try natgrid version?

2011-12-21 Thread Jeff Whitaker

On 12/21/11 12:31 AM, Brad Malone wrote:
Hi, I'm still working on my interpolating from an irregularly space 
grid and then running pcolormesh on the resulting output. With some of 
the newer data I've been plotting I've noticed that my plots are 
complete garbage. I realized that this was actually because of the 
output from griddata rather than some problem with 
pcolormesh/pcolor/etc (basically I get huge negative values like 
-8 from the interpolation when all of my data points lie within 
[0,20]) .


Googling I found out that the default griddata has some problems, and 
that there is a better, more robust version available through natgrid. 
 I downloaded the natgrid-0.2.1 package from here 
http://sourceforge.net/projects/matplotlib/files%2Fmatplotlib-toolkits%2Fnatgrid-0.2/. 



My question now is, how do I install this and give it a shot? I'm 
running on Ubuntu (or Xubuntu rather). The README doesn't seem to have 
any directions.

Brad:

python setup.py install should do it.  matplotlib will automatically use 
it if it's installed.


-Jeff


Also, let's say that this new griddata doesn't work for me, is there 
something else I could try? The interpolation problems are strange, 
because I can break my data into 3 segments (I read 3 files to obtain 
the data so this is the natural way to do it) and I can plot and 
interpolate correctly any segment individually. It's only when I do 
all 3 segments together that the interpolation begins to fail.


Any ideas?

Thanks for the continued help!

Brad


--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev


___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Griddata failling; how to try natgrid version?

2011-12-21 Thread Brad Malone
Jeff,

Thanks. That indeed did work (after downloading python-dev package). I just
didn't know that 'install' was the argument that I was supposed to pass to
it =)

After installing I tried griddata again. My input data was originally a
list. The new griddata didn't like this and so I simply used
a=array(thelist) to convert to an array and tried again. It took quite a
bit longer than the old griddata, but the resulting output now looks
correct! Better a slow and correct answer than a fast and garbage one.

Thanks again Jeff (and thanks for the new griddata if you are the one that
made it)!

Brad

On Wed, Dec 21, 2011 at 5:55 AM, Jeff Whitaker  wrote:

>  On 12/21/11 12:31 AM, Brad Malone wrote:
>
> Hi, I'm still working on my interpolating from an irregularly space grid
> and then running pcolormesh on the resulting output. With some of the newer
> data I've been plotting I've noticed that my plots are complete garbage. I
> realized that this was actually because of the output from griddata rather
> than some problem with pcolormesh/pcolor/etc (basically I get huge negative
> values like -8 from the interpolation when all of my data points lie
> within [0,20]) .
>
>  Googling I found out that the default griddata has some problems, and
> that there is a better, more robust version available through natgrid.  I
> downloaded the natgrid-0.2.1 package from here
> http://sourceforge.net/projects/matplotlib/files%2Fmatplotlib-toolkits%2Fnatgrid-0.2/
> .
>
>  My question now is, how do I install this and give it a shot? I'm
> running on Ubuntu (or Xubuntu rather). The README doesn't seem to have any
> directions.
>
> Brad:
>
> python setup.py install should do it.  matplotlib will automatically use
> it if it's installed.
>
> -Jeff
>
>
>  Also, let's say that this new griddata doesn't work for me, is there
> something else I could try? The interpolation problems are strange, because
> I can break my data into 3 segments (I read 3 files to obtain the data so
> this is the natural way to do it) and I can plot and interpolate correctly
> any segment individually. It's only when I do all 3 segments together that
> the interpolation begins to fail.
>
>  Any ideas?
>
>  Thanks for the continued help!
>
>  Brad
>
>
> --
> Write once. Port to many.
> Get the SDK and tools to simplify cross-platform app development. Create
> new or port existing apps to sell to consumers worldwide. Explore the
> Intel AppUpSM program developer opportunity. 
> appdeveloper.intel.com/joinhttp://p.sf.net/sfu/intel-appdev
>
>
>
> ___
> Matplotlib-users mailing 
> listMatplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users