Re: [Matplotlib-users] Speeding up pcolor plot
Hey again, Brad, Brad Malone, on 2011-12-19 23:44, wrote: Hi, I am plotting a grid with pcolor. Below I've got a 1000x1000 grid. xi=linspace(-0.1,x[-1]+2,1000) yi=linspace(-0.1,maxfreq+10,1000) print 'Calling griddata...' zi=griddata(x,y,z,xi,yi,interp='nn') plt.pcolor(xi,yi,zi,cmap=plt.cm.hot) ... How could I modify my above data (which is in xi,yi,and zi) to work with imshow (which seems to take 1 argument for data). Try either: plt.matshow(zi,cmap=plt.cm.hot) or plt.imshow(zi,cmap=plt.cm.hot) The first should be the quickest - it doesn't do any fancy interpolation, and actually just passes some arguments to the second. Using imshow directly, however, allows you to set a different type of interpolation, should you desire it. If you want xi and yi to be accurately reflect in the plot, you might have to play around with changing the axis formatters (though there might be an easier way of doing that, which escapes me right now) best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 signature.asc Description: Digital signature -- 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
[Matplotlib-users] animation.FuncAnimation
Hi all, How do I use animation.FuncAnimation to plot real-life data from parsing a text file ? import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import sys import time import re x = [] # x y = [] # y fig = plt.figure() ax= fig.add_subplot(111) curve,= ax.plot([],[],lw=2) ax.set_xlim(0,5) ax.grid() def tail_f(file): interval = 1.0 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 if not line: time.sleep(interval) file.seek(where) # seek(offset[, whence]) - None. Move to new file position. else: yield line def run(): for line in tail_f(open(sys.argv[1])): print line, 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 # # # run() plt.show() The text file looks like x=0.0 y=0.0 blabla x=1.0 y=1.0 blabla x=2.0 y=4.0 blabla ... 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] animation.FuncAnimation
On Tue, Dec 20, 2011 at 8:00 AM, Nils Wagner nwag...@iam.uni-stuttgart.dewrote: Hi all, How do I use animation.FuncAnimation to plot real-life data from parsing a text file ? import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import sys import time import re x = [] # x y = [] # y fig = plt.figure() ax= fig.add_subplot(111) curve,= ax.plot([],[],lw=2) ax.set_xlim(0,5) ax.grid() def tail_f(file): interval = 1.0 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 if not line: time.sleep(interval) file.seek(where) # seek(offset[, whence]) - None. Move to new file position. else: yield line def run(): for line in tail_f(open(sys.argv[1])): print line, 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 # # # run() plt.show() The text file looks like x=0.0 y=0.0 blabla x=1.0 y=1.0 blabla x=2.0 y=4.0 blabla ... Nils Nils, I think the key thing to keep in mind when using any of the animators is that the animator in question is driving the calls to update the plot from its own event source. In most cases, that source is a timer. For FuncAnimator, the function passed into the constructor must perform whatever actions are needed for a single update. What I would do is Subclass FuncAnimator so that its constructor will create an empty Line2D object that has already been added to an axes object (or you can pass an empty one yourself as an argument to the function). In the function run(), you would obtain the next chunk of data and then update the Line2D object with that information. I think you have it mostly done, just need a few extra pieces. Cheers! Ben Root -- 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] animation.FuncAnimation
On Tue, Dec 20, 2011 at 8:00 AM, Nils Wagner nwag...@iam.uni-stuttgart.de 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 -- 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] Speeding up pcolor plot
HI Paul, Thanks. I didn't realize it was that simple (appears that doing this essentially plots everything against integers in x and y). This will be a good backup plan if I can't get pcolor to work, although as you say, I'll have to fiddle around some with the axis formatters and such I suppose to get a good final plot out of this. Best, Brad On Tue, Dec 20, 2011 at 12:12 AM, Paul Ivanov pivanov...@gmail.com wrote: Hey again, Brad, Brad Malone, on 2011-12-19 23:44, wrote: Hi, I am plotting a grid with pcolor. Below I've got a 1000x1000 grid. xi=linspace(-0.1,x[-1]+2,1000) yi=linspace(-0.1,maxfreq+10,1000) print 'Calling griddata...' zi=griddata(x,y,z,xi,yi,interp='nn') plt.pcolor(xi,yi,zi,cmap=plt.cm.hot) ... How could I modify my above data (which is in xi,yi,and zi) to work with imshow (which seems to take 1 argument for data). Try either: plt.matshow(zi,cmap=plt.cm.hot) or plt.imshow(zi,cmap=plt.cm.hot) The first should be the quickest - it doesn't do any fancy interpolation, and actually just passes some arguments to the second. Using imshow directly, however, allows you to set a different type of interpolation, should you desire it. If you want xi and yi to be accurately reflect in the plot, you might have to play around with changing the axis formatters (though there might be an easier way of doing that, which escapes me right now) best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAk7wQ30ACgkQe+cmRQ8+KPdN8gCfY3SlI7F5zoXVrDL86VRyq3pC SwwAn2bc6MBQjasKVxVzrvVRxaPJKiUP =NmWr -END PGP SIGNATURE- -- 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] Speeding up pcolor plot
On Tue, Dec 20, 2011 at 9:22 AM, Brad Malone brad.mal...@gmail.com wrote: HI Paul, Thanks. I didn't realize it was that simple (appears that doing this essentially plots everything against integers in x and y). This will be a good backup plan if I can't get pcolor to work, although as you say, I'll have to fiddle around some with the axis formatters and such I suppose to get a good final plot out of this. Best, Brad On Tue, Dec 20, 2011 at 12:12 AM, Paul Ivanov pivanov...@gmail.comwrote: Hey again, Brad, Brad Malone, on 2011-12-19 23:44, wrote: Hi, I am plotting a grid with pcolor. Below I've got a 1000x1000 grid. xi=linspace(-0.1,x[-1]+2,1000) yi=linspace(-0.1,maxfreq+10,1000) print 'Calling griddata...' zi=griddata(x,y,z,xi,yi,interp='nn') plt.pcolor(xi,yi,zi,cmap=plt.cm.hot) ... How could I modify my above data (which is in xi,yi,and zi) to work with imshow (which seems to take 1 argument for data). Try either: plt.matshow(zi,cmap=plt.cm.hot) or plt.imshow(zi,cmap=plt.cm.hot) The first should be the quickest - it doesn't do any fancy interpolation, and actually just passes some arguments to the second. Using imshow directly, however, allows you to set a different type of interpolation, should you desire it. If you want xi and yi to be accurately reflect in the plot, you might have to play around with changing the axis formatters (though there might be an easier way of doing that, which escapes me right now) best, -- Paul Ivanov You may also want to try: plt.pcolormesh(xi,yi,zi,cmap=plt.cm.hot) If I remember correctly, pcolormesh is faster but a bit more restrictive. (I think it's slower than matshow and imshow). -Tony P.S. I never knew about matshow; thanks Paul! -- 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] basemap UTM conversion discrepancy
Jeff, Here are the versions that I'm working with: basemap:1.0.2 matplotlib: 1.1.0 numpy: 1.5.1 libgeos:3.2.0 I ran the coordinate conversion on another computer with the same system configuration and there it works as it should. I have tried to clean my system and removed all the packages related to basemap (geos, proj) and only reinstalled the required libgeos packages. I deleted the basemap directory from the /usr/local/lib/python2.7/dist-packages. I deleted the _geoslib.so from /usr/local/lib/python2.7/dist-packages. After that I rebuilt and installed basemap. The problem still remains. Don't know what's going wrong. Stefan. Am Montag, den 19.12.2011, 18:33 -0700 schrieb Jeff Whitaker: On 12/19/11 4:47 PM, Stefan Mertl wrote: Hi Jeff, I'm not an expert in coordinate transformation and the usage of proj, so I can't exactly tell you if I have all the datum files installed. If you could tell me what files could be missing I could search for them. What makes me wonder, is that you get the results that my mpl_toolkits.basemap.pyproj.Proj usage produced. When using some conversion tools on the internet like http://home.hiwaay.net/~taylorc/toolbox/geodesy/datumtrans/ or http://www.uwgb.edu/dutchs/UsefulData/ConvertUTMNoOZ.HTM I get the results that my commandline proj produces. So I think that something with my pyproj installation is not working. Regards, Stefan. Stefan: I mis-spoke in my earlier email - the answer I get with pyproj is the same as you get with command line proj. What version of basemap do you have installed? -Jeff Am Montag, den 19.12.2011, 15:51 -0700 schrieb Jeff Whitaker: On 12/19/11 2:23 PM, Stefan Mertl wrote: Hello, I'm starting to use the mpl_toolkits.basemap.pyproj.Proj class to do lon/lat to UTM coordinate conversion. I did some tests and noticed that there is a discrepancy between the mpl_toolkits.basemap.pyproj.Proj output and the proj commandline tool output. e.g.: I'm converting the coordinates lat=48.2; lon=16.5 to UTM coordinates UTM zone 33 with WGS84 ellipse. I'm using the following proj4 string for the conversion: +proj=utm +zone=33 +ellps=WGS84 +datum=WGS84 +units=m +no_defs The output using mpl_toolkits.basemap.pyproj.Proj is: x: 611458.865; y: 5339596.032 The proj commandline tool using the same proj4 string gives: x: 611458.69 y: 5339617.54 As you can see, the y coordinate differs significantly. Here's the code used with the basemap pyproy classes: -- from mpl_toolkits.basemap.pyproj import Proj # I got the proj string from # http://spatialreference.org/ref/epsg/32633 myProj = Proj(+proj=utm +zone=33 +ellps=WGS84 +datum=WGS84 +units=m +no_defs) lat = 48.2 lon = 16.5 (x,y) = myProj(lon, lat) print x: %.3f; y: %.3f % (x,y) --- Can somebody explain me this behavior? Regards, Stefan. Stefan: When I run this test, I get the same answer with both, and it is the same as the answer basemap.pyproj gave you. I suspect you didn't install the extra datum files with your command-line proj distribution. -Jeff -- 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 signature.asc Description: This is a digitally signed message part -- 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] Speeding up pcolor plot
Tony, Thanks for the pcolormesh suggestion! It is quite a bit faster than pcolor for me (maybe 50-100x faster)! Best, Brad On Tue, Dec 20, 2011 at 10:10 AM, Tony Yu tsy...@gmail.com wrote: On Tue, Dec 20, 2011 at 9:22 AM, Brad Malone brad.mal...@gmail.comwrote: HI Paul, Thanks. I didn't realize it was that simple (appears that doing this essentially plots everything against integers in x and y). This will be a good backup plan if I can't get pcolor to work, although as you say, I'll have to fiddle around some with the axis formatters and such I suppose to get a good final plot out of this. Best, Brad On Tue, Dec 20, 2011 at 12:12 AM, Paul Ivanov pivanov...@gmail.comwrote: Hey again, Brad, Brad Malone, on 2011-12-19 23:44, wrote: Hi, I am plotting a grid with pcolor. Below I've got a 1000x1000 grid. xi=linspace(-0.1,x[-1]+2,1000) yi=linspace(-0.1,maxfreq+10,1000) print 'Calling griddata...' zi=griddata(x,y,z,xi,yi,interp='nn') plt.pcolor(xi,yi,zi,cmap=plt.cm.hot) ... How could I modify my above data (which is in xi,yi,and zi) to work with imshow (which seems to take 1 argument for data). Try either: plt.matshow(zi,cmap=plt.cm.hot) or plt.imshow(zi,cmap=plt.cm.hot) The first should be the quickest - it doesn't do any fancy interpolation, and actually just passes some arguments to the second. Using imshow directly, however, allows you to set a different type of interpolation, should you desire it. If you want xi and yi to be accurately reflect in the plot, you might have to play around with changing the axis formatters (though there might be an easier way of doing that, which escapes me right now) best, -- Paul Ivanov You may also want to try: plt.pcolormesh(xi,yi,zi,cmap=plt.cm.hot) If I remember correctly, pcolormesh is faster but a bit more restrictive. (I think it's slower than matshow and imshow). -Tony P.S. I never knew about matshow; thanks Paul! -- 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] Speeding up pcolor plot
On 12/20/2011 10:48 AM, Brad Malone wrote: Tony, Thanks for the pcolormesh suggestion! It is quite a bit faster than pcolor for me (maybe 50-100x faster)! There is also the Axes.pcolorfast() method. It has no pylab wrapper, and it is fussier than the others about its input arguments, but it uses the fastest method that the input grid permits. In your case it would be the speed of imshow, which is faster than pcolormesh. http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.pcolorfast Note that like pcolor and pcolormesh its grid is based on the specification of the boundaries, not the centers, but unlike pcolormesh and pcolor it will not automatically chop off a row and a column of the 2-D color array to be plotted if you give it a grid with the same dimensions as the color array. Eric Best, Brad On Tue, Dec 20, 2011 at 10:10 AM, Tony Yu tsy...@gmail.com mailto:tsy...@gmail.com wrote: On Tue, Dec 20, 2011 at 9:22 AM, Brad Malone brad.mal...@gmail.com mailto:brad.mal...@gmail.com wrote: HI Paul, Thanks. I didn't realize it was that simple (appears that doing this essentially plots everything against integers in x and y). This will be a good backup plan if I can't get pcolor to work, although as you say, I'll have to fiddle around some with the axis formatters and such I suppose to get a good final plot out of this. Best, Brad On Tue, Dec 20, 2011 at 12:12 AM, Paul Ivanov pivanov...@gmail.com mailto:pivanov...@gmail.com wrote: Hey again, Brad, Brad Malone, on 2011-12-19 23:44, wrote: Hi, I am plotting a grid with pcolor. Below I've got a 1000x1000 grid. xi=linspace(-0.1,x[-1]+2,1000) yi=linspace(-0.1,maxfreq+10,1000) print 'Calling griddata...' zi=griddata(x,y,z,xi,yi,interp='nn') plt.pcolor(xi,yi,zi,cmap=plt.cm.hot) ... How could I modify my above data (which is in xi,yi,and zi) to work with imshow (which seems to take 1 argument for data). Try either: plt.matshow(zi,cmap=plt.cm.hot) or plt.imshow(zi,cmap=plt.cm.hot) The first should be the quickest - it doesn't do any fancy interpolation, and actually just passes some arguments to the second. Using imshow directly, however, allows you to set a different type of interpolation, should you desire it. If you want xi and yi to be accurately reflect in the plot, you might have to play around with changing the axis formatters (though there might be an easier way of doing that, which escapes me right now) best, -- Paul Ivanov You may also want to try: plt.pcolormesh(xi,yi,zi,cmap=plt.cm.hot) If I remember correctly, pcolormesh is faster but a bit more restrictive. (I think it's slower than matshow and imshow). -Tony P.S. I never knew about matshow; thanks Paul! -- 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
[Matplotlib-users] Griddata failling; how to try natgrid version?
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. 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