[Tutor] read in ascii and plot
waynejwerner at gmail.com
Tue Dec 1 02:26:33 CET 2009
On Mon, Nov 30, 2009 at 5:55 PM, questions anon <questions.anon at gmail.com>wrote:
> I would like to read in two columns of data from a *.txt file
> I type
> import pylab
> and then receive an error.
> How do I point it to each column and do I need to do anything about the
> space gap between the two columns?
> Thanks in advance.
A sample of the data is always helpful, but I'll take a shot in the dark.
If you have data like this:
And those are x y pairs you could do something like this:
f = open('input.txt')
#List comprehension to read all the lines as [[x1, y1], [x2, y2], ... [xn,
data = [line.split() for line in f]
# Reorient values as [(x1, x2,... xn), (y1, y2, ... yn)]
data = zip(*data)
# plot the xy vals
That should be something along the lines of what you're looking for.
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor