Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.
Close
From: Lionel Roubeyrie <lroubeyrie@li...>  20070905 07:50:23

Hi Ping, don't know if it could help you : from pylab import * > d = Table("xyt.dat") x,y,t = load("xyt.dat", unpack=true) > d.plot("x", "t") # make a plot of x vs. t, N points are drawn plot(t, x) > d.plot("x") # make a histogram plot of x, N entries in the histogram bar(range(len(x)), x) > d.plot("x", "y < 3") # make a histogram plot of x where y is less than 3. ind = find(y < 3) xi = x[ind] bar(range(len(xi)), xi) Cheers 
From: Ping Yeh <ping.yeh@gm...>  20070905 07:18:47

Hi, I checked the manual and briefly searched the mailing list but did not find this... Is there a tablelike data type with rows as events and columns as attributes that I can make plots with? This is called "ntuple" in the high energy physics community. Let me illustrate with an example. Assume that an event consists of 3 attributes (x, y, t). With N events we have a table of N x 3 data items. Assume that the data items are read from a file "xyt.dat". d = Table("xyt.dat") d.plot("x", "t") # make a plot of x vs. t, N points are drawn d.plot("x") # make a histogram plot of x, N entries in the histogram d.plot("x", "y < 3") # make a histogram plot of x where y is less than 3. # that is, only {x[i]  y[i] < 3} are used to make the histogram If there is no existing modules for this I'll go ahead write one. :) cheers, Ping 
From: Eric Firing <efiring@ha...>  20070905 07:36:21

Ping Yeh wrote: > Hi, > > I checked the manual and briefly searched the mailing list but did not > find this... Is there a tablelike data type with rows as events and > columns as attributes that I can make plots with? This is called > "ntuple" in the high energy physics community. > > Let me illustrate with an example. Assume that an event consists of 3 > attributes (x, y, t). With N events we have a table of N x 3 data > items. Assume that the data items are read from a file "xyt.dat". > > d = Table("xyt.dat") > d.plot("x", "t") # make a plot of x vs. t, N points are drawn > d.plot("x") # make a histogram plot of x, N entries in the histogram > d.plot("x", "y < 3") # make a histogram plot of x where y is less than 3. > # that is, only {x[i]  y[i] < 3} are used to make the histogram > > If there is no existing modules for this I'll go ahead write one. :) There is nothing quite like this. As a starting point, though, you should become familiar with the ability of numpy to handle record arrays; your table data type sounds like a numpy record array. Matplotlib is a plotting library built on the numpy Ndimensional array library. Eric 
From: Ping Yeh <ping.yeh@gm...>  20070905 08:33:23

2007/9/5, Eric Firing <efiring@...>: > Ping Yeh wrote: > [snip] > > > > If there is no existing modules for this I'll go ahead write one. :) > > There is nothing quite like this. As a starting point, though, you > should become familiar with the ability of numpy to handle record > arrays; your table data type sounds like a numpy record array. > Matplotlib is a plotting library built on the numpy Ndimensional array > library. > > Eric > Hi Eric, Thanks for the info. I searched for the numpy record array and it is indeed very close to what I want for the data storage! Thanks! Just one quick question, though (I admit I don't have much experience with numpy...). Can a record array store string data? I'll have some of these in the attribute data, not used for plotting but needed for other purposes. Thanks, Ping 
From: Lionel Roubeyrie <lroubeyrie@li...>  20070905 07:50:23

Hi Ping, don't know if it could help you : from pylab import * > d = Table("xyt.dat") x,y,t = load("xyt.dat", unpack=true) > d.plot("x", "t") # make a plot of x vs. t, N points are drawn plot(t, x) > d.plot("x") # make a histogram plot of x, N entries in the histogram bar(range(len(x)), x) > d.plot("x", "y < 3") # make a histogram plot of x where y is less than 3. ind = find(y < 3) xi = x[ind] bar(range(len(xi)), xi) Cheers 
From: Ping Yeh <ping.yeh@gm...>  20070905 08:42:42

Hi Lionel, Thanks for the tips. The histogram plot I need can be done by hist(x). :) I tried your commands and I like the find() function! However, xi = x[ind] failed with an "IndexError: invalid index". The same operation can be done with xi = array([x[i] for i in ind]) but if a numpy function can do that it may be faster for large arrays. cheers, Ping 2007/9/5, Lionel Roubeyrie <lroubeyrie@...>: > Hi Ping, > don't know if it could help you : > > from pylab import * > > > d = Table("xyt.dat") > x,y,t = load("xyt.dat", unpack=true) > > > d.plot("x", "t") # make a plot of x vs. t, N points are drawn > plot(t, x) > > > d.plot("x") # make a histogram plot of x, N entries in the histogram > bar(range(len(x)), x) > > > d.plot("x", "y < 3") # make a histogram plot of x where y is less than 3. > ind = find(y < 3) > xi = x[ind] > bar(range(len(xi)), xi) > > Cheers > > >  > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > 
From: Ping Yeh <ping.yeh@gm...>  20070905 10:09:36

Hello, Thanks to quick hints/tips from Eric and Lionel, I have a module for conditional plotting and histogramming without defining a table type! It works with numerical arrays quite well, but does not work on string arrays in conditions. I paste the code below since they are quite short. Hope that's not considered spam on this list. :) cheers and thanks, Ping from pylab import * def __prepare(arg): cond = arg[1] indices = find(cond) toplot = [] atype = type(array([0,1])) for vec in arg[:1]: if type(vec) == type(""): toplot.append(vec) if type(vec) == atype: toplot.append(array([vec[i] for i in indices])) return toplot def cplot(*arg, **kw): '''Make a conditional plot. Example: cplot(t, x, y > 3) => a plot of { (t[i],x[i])  y[i] > 3} cplot(x, y > 3) => a plot of { (i,x[i])  y[i] > 3} The condition string can have multiple conditions joined by logical operators &  ^. All keyword arguments are passed intact to plot(). ''' toplot = __prepare(arg) return plot(*toplot, **kw) def chist(*arg, **kw): '''Make a conditional histogram. Example: chist(x, y > 3) => a histogram plot of {x[i]  y[i] > 3} The condition string can have multiple conditions joined by logical operators &  ^. All keyword arguments are passed intact to hist(). ''' toplot = __prepare(arg) return hist(*toplot, **kw) def testcplot(): t = arange(0,1.0, 0.01) x = sin(t*2*pi) y = exp(t/0.5) plot(t, x) plot(t, y) cplot(t, x, "o", y<0.2) if __name__ == '__main__': testcplot() 
From: Eric Firing <efiring@ha...>  20070905 18:12:52

Ping Yeh wrote: > 2007/9/5, Eric Firing <efiring@...>: >> Ping Yeh wrote: >> [snip] >>> If there is no existing modules for this I'll go ahead write one. :) >> There is nothing quite like this. As a starting point, though, you >> should become familiar with the ability of numpy to handle record >> arrays; your table data type sounds like a numpy record array. >> Matplotlib is a plotting library built on the numpy Ndimensional array >> library. >> >> Eric >> > > Hi Eric, > > Thanks for the info. I searched for the numpy record array and it is > indeed very close to what I want for the data storage! Thanks! > > Just one quick question, though (I admit I don't have much experience > with numpy...). Can a record array store string data? I'll have some > of these in the attribute data, not used for plotting but needed for > other purposes. Yes. Here is an example: In [27]:dd1 = numpy.dtype({'names': ['x', 'y', 'i', 'comment'], 'formats': ['<f8', '<f8', '<i4', 'S20']}) In [28]:xx = numpy.array([(1.1, 2.2, 1, 'first'), (1.2, 2.3, 2, 'second')], dtype=dd1) In [29]:xx Out[29]: array([(1.1000000000000001, 2.2000000000000002, 1, 'first'), (1.2, 2.2999999999999998, 2, 'second')], dtype=[('x', '<f8'), ('y', '<f8'), ('i', '<i4'), ('comment', 'S20')]) In [30]:xx['x'] Out[30]:array([ 1.1, 1.2]) In [31]:xx['comment'] Out[31]: array(['first', 'second'], dtype='S20') There is one nonobvious thing to note: in line 28, each record must be a *tuple*, not a *list*. Note also that you must allow enough space for the maximum length of string. Alternatively, the strings can be stored as objects: In [32]:dd2 = numpy.dtype({'names': ['x', 'y', 'i', 'comment'], 'formats': ['<f8', '<f8', '<i4', 'O']}) In [33]:xx = numpy.array([(1.1, 2.2, 1, 'first'), (1.2, 2.3, 2, 'second')], dtype=dd2) In [34]:xx['comment'] Out[34]:array([first, second], dtype=object) In [35]:xx['x'] Out[35]:array([ 1.1, 1.2]) Eric 