[Numpy-discussion] loading and filtering data for matplotlib

Resmi l.resmi@gmail....
Tue Oct 26 09:57:43 CDT 2010


Hi
 I'm new to python. I'm trying to plot a data set in matplotlib.

 The data is a mixture of strings and floats, has four columns
(col[0],col[1],col[2],col[3]) and it looks like:

R       -2.29350   0.50340   0.480E-01
R       -2.25903   0.50740   0.480E-01
SU      -2.19457   0.16200   0.800E-01
SU      -2.13237   0.14600   0.800E-01

What I want to do is to plot the SU filtered entries alone as col[1]:col[2]

I wrote a script to read the data, how can I make x1 and SUx2 as
arrays? Right now matplotlib only plots the last value obviously. Or
is there a different/better way to slice just the SU entries and make
them as a separate array? My actual data file has many more entries
with more filters and I want to make a plot for each of the filters
with col[1]:col[2]

import pylab
import numpy
#Loading and reading data
data=numpy.loadtxt('file.dat',dtype=[('filt','S4'),('x1','f8'),('x2','f8'),('x3','f8')])
filt=data['filt']
for i in range(0,len(filt),1):
 if filt[i] == 'SU':
  x1=data['x1'][i]
  SUx2=data['x2'][i]
#print x1,SUx2
pylab.plot(x1,SUx2,'bs')
pylab.show()


More information about the NumPy-Discussion mailing list