[AstroPy] question on matplotlib's loadtxt
Grigoris Maravelias
gr.maravelias@gmail....
Fri Nov 4 08:56:21 CDT 2011
Hello to all! I would like to ask about an error I face with
matplotlib's loadtxt...
Suppose that we have a file (called "test.test") with 6 columns like:
1496548. 862.235400937 14.008 0 20110523.201416 tth*g
1690289. 919.424007603 13.875 0 20110523.221527 hgf4
1667241. 996.262754039 13.890 0 20110524.001639 nb.mj
739181.6 881.1753527 14.774 0 20110524.010203 vbfhg
When I use
x, y = loadtxt('test.test', unpack=True, usecols=(0,1), dtype=(float,float))
it prints normally the first and second column.
If I add another column like:
x, y, z = loadtxt('test.test', unpack=True,usecols=(0,1,3),
dtype=(float,float,float))
the output is this:
File "/usr/lib/python2.7/site-packages/numpy/lib/io.py", line 584, in
loadtxt
dtype = np.dtype(dtype)
TypeError: data type not understood
Even if I use a dictionary, like:
dt = dtype({'names':['n1','n2','n3'],'formats':[float,float,float]})
x, y, z = loadtxt('test.test', unpack=True, usecols=(0,1,2) , dtype=dt)
the output is the same as previous.
Additionaly, when I am trying to load the last column as strings:
x, y = loadtxt('test.test', delimiter=' ', unpack=True,usecols=(0,5),
dtype=(float,'S5'))
I get this error:
File "/usr/lib/python2.7/site-packages/numpy/lib/io.py", line 584, in
loadtxt
dtype = np.dtype(dtype)
ValueError: mismatch in size of old and new data-descriptor
What am I doing wrong ? I am sorry if it is something really obvious ...
but I am unable to find it...
Thanks for your time!
Grigoris
More information about the AstroPy
mailing list