loadtxt/usecols -> list index out of range

Hi,

I'm trying to make my first matplotlib-plot from a datafile. The
datafile is tab-separated and looks like this:
# x-axis y-axis
0 1
1 2
2 3
3 4
4 5
5 6

So my ploting-script is:

#!/usr/bin/env python
from pylab import *
import numpy as np

inputfile = '/home/manu/matplotlib-examples/simple_plot.py'

x,y = np.loadtxt(inputfile, dtype='float', comments='#',
delimiter="\t", converters=None, skiprows=0, usecols=(0,1),
unpack=True)
plot(x, y, linewidth=1.0)
xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
show()

It worked fine for me once, but as I tried to start the script again I
get an IndexError:

Traceback (most recent call last):
  File "./simple_plot.py", line 7, in <module>
    x,y = np.loadtxt(inputfile, dtype='float', comments='#',
delimiter="\t", converters=None, skiprows=0, usecols=(0,1),
unpack=True)
  File "/usr/lib/python2.6/dist-packages/numpy/lib/io.py", line 486, in loadtxt
    vals = [vals[i] for i in usecols]
IndexError: list index out of range

Seems to me that usecols has "to much input" (don't know how to call
it), but why did it work before?

Manuel

Check your data file. What you posted to the list is copy/pasting as
8 spaces for me, but you are specifying delimiter='\t'. I'd try just
not specifying delimiter or passing in delimiter=None.

Ryan

···

On Mon, Nov 16, 2009 at 4:34 PM, Manuel Wittchen <manuel.wittchen@...287...> wrote:

Hi,

I'm trying to make my first matplotlib-plot from a datafile. The
datafile is tab-separated and looks like this:
# x-axis y-axis
0 1
1 2
2 3
3 4
4 5
5 6

So my ploting-script is:

#!/usr/bin/env python
from pylab import *
import numpy as np

inputfile = '/home/manu/matplotlib-examples/simple_plot.py'

x,y = np.loadtxt(inputfile, dtype='float', comments='#',
delimiter="\t", converters=None, skiprows=0, usecols=(0,1),
unpack=True)
plot(x, y, linewidth=1.0)
xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
show()

It worked fine for me once, but as I tried to start the script again I
get an IndexError:

Traceback (most recent call last):
File "./simple_plot.py", line 7, in <module>
x,y = np.loadtxt(inputfile, dtype='float', comments='#',
delimiter="\t", converters=None, skiprows=0, usecols=(0,1),
unpack=True)
File "/usr/lib/python2.6/dist-packages/numpy/lib/io.py", line 486, in loadtxt
vals = [vals[i] for i in usecols]
IndexError: list index out of range

Seems to me that usecols has "to much input" (don't know how to call
it), but why did it work before?

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Hi,

I’m trying to make my first matplotlib-plot from a datafile. The

datafile is tab-separated and looks like this:

x-axis y-axis

0 1

1 2

2 3

3 4

4 5

5 6

So my ploting-script is:

#!/usr/bin/env python

from pylab import *

import numpy as np

inputfile = ‘/home/manu/matplotlib-examples/simple_plot.py’

x,y = np.loadtxt(inputfile, dtype=‘float’, comments=’#’,

delimiter="\t", converters=None, skiprows=0, usecols=(0,1),

unpack=True)

plot(x, y, linewidth=1.0)

xlabel(‘time (s)’)

ylabel(‘voltage (mV)’)

title(‘About as simple as it gets, folks’)

grid(True)

show()

It worked fine for me once, but as I tried to start the script again I

get an IndexError:

Traceback (most recent call last):

File “./simple_plot.py”, line 7, in

x,y = np.loadtxt(inputfile, dtype='float', comments='#',

delimiter="\t", converters=None, skiprows=0, usecols=(0,1),

unpack=True)

File “/usr/lib/python2.6/dist-packages/numpy/lib/io.py”, line 486, in loadtxt

vals = [vals[i] for i in usecols]

IndexError: list index out of range

Seems to me that usecols has “to much input” (don’t know how to call

it), but why did it work before?

This is an interesting behaviour. I don’t exactly know why it happens as you described, but If you would like something working try this:

Slightly modify your data file to be consistent --equal spaces or tabs

x,y = np.loadtxt(“data”, dtype=‘float’, delimiter=" ", skiprows=1).T

As simple as it gets, the above line successfully loads the data.

Give it a try…

···

On Mon, Nov 16, 2009 at 4:34 PM, Manuel Wittchen <manuel.wittchen@…287…> wrote:

Manuel


Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day

trial. Simplify your report design, integration and deployment - and focus on

what you do best, core application coding. Discover what’s new with

Crystal Reports now. http://p.sf.net/sfu/bobj-july


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Gökhan

********Problem solved!**********
Thanks for all the tipps, but they didn't fix the problem. There never
was a problem with usecols or something. My mistake was, that I've
used the plot-script-file as the datainput-file, by accident.
Sorry for wasting your time with this.
I think it's too late (00:34 AM here), I have to go to bed and get
some sleep....

Manuel

2009/11/16 Gökhan Sever <gokhansever@...287...>:

···

On Mon, Nov 16, 2009 at 4:34 PM, Manuel Wittchen <manuel.wittchen@...985.....> > wrote:

Hi,

I'm trying to make my first matplotlib-plot from a datafile. The
datafile is tab-separated and looks like this:
# x-axis y-axis
0 1
1 2
2 3
3 4
4 5
5 6

So my ploting-script is:

#!/usr/bin/env python
from pylab import *
import numpy as np

inputfile = '/home/manu/matplotlib-examples/simple_plot.py'

x,y = np.loadtxt(inputfile, dtype='float', comments='#',
delimiter="\t", converters=None, skiprows=0, usecols=(0,1),
unpack=True)
plot(x, y, linewidth=1.0)
xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
show()

It worked fine for me once, but as I tried to start the script again I
get an IndexError:

Traceback (most recent call last):
File "./simple_plot.py", line 7, in <module>
x,y = np.loadtxt(inputfile, dtype='float', comments='#',
delimiter="\t", converters=None, skiprows=0, usecols=(0,1),
unpack=True)
File "/usr/lib/python2.6/dist-packages/numpy/lib/io.py", line 486, in
loadtxt
vals = [vals[i] for i in usecols]
IndexError: list index out of range

Seems to me that usecols has "to much input" (don't know how to call
it), but why did it work before?

This is an interesting behaviour. I don't exactly know why it happens as you
described, but If you would like something working try this:

Slightly modify your data file to be consistent --equal spaces or tabs

x,y = np.loadtxt("data", dtype='float', delimiter=" ", skiprows=1).T

As simple as it gets, the above line successfully loads the data.

Give it a try...

Manuel

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Gökhan