On Mon, Nov 16, 2009 at 4:34 PM, Manuel Wittchen <manuel.wittc...@gmail.com> 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?
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 -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma ------------------------------------------------------------------------------ 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