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.

## Re: [Matplotlib-users] table data type and plot functions?

 Re: [Matplotlib-users] table data type and plot functions? From: Lionel Roubeyrie - 2007-09-05 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 ```

 [Matplotlib-users] table data type and plot functions? From: Ping Yeh - 2007-09-05 07:18:47 ```Hi, I checked the manual and briefly searched the mailing list but did not find this... Is there a table-like 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 ```
 Re: [Matplotlib-users] table data type and plot functions? From: Eric Firing - 2007-09-05 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 table-like 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 N-dimensional array library. Eric ```
 Re: [Matplotlib-users] table data type and plot functions? From: Ping Yeh - 2007-09-05 08:33:23 ```2007/9/5, Eric Firing : > 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 N-dimensional 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 ```
 Re: [Matplotlib-users] table data type and plot functions? From: Lionel Roubeyrie - 2007-09-05 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 ```
 Re: [Matplotlib-users] table data type and plot functions? From: Ping Yeh - 2007-09-05 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 : > 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/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ```
 Re: [Matplotlib-users] table data type and plot functions? From: Ping Yeh - 2007-09-05 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() ```
 Re: [Matplotlib-users] table data type and plot functions? From: Eric Firing - 2007-09-05 18:12:52 ```Ping Yeh wrote: > 2007/9/5, Eric Firing : >> 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 N-dimensional 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': ['