I would now like to add a line of best fit. I think the command is polyfit()??<br>But I can't seem to get it to work<br><br>f=open('e:/testscatter.txt')<br>data=[map(float,line.split()) for line in f]<br>x, y=zip(*data)<br>
pylab.polyfit(x,y,1)<br>pylab.scatter(x,y)<br>pylab.show()<br><br>Any feedback will be greatly appreciated.<br><br><br><br><div class="gmail_quote">On Mon, Nov 30, 2009 at 7:03 PM, Kent Johnson <span dir="ltr"><<a href="mailto:kent37@tds.net">kent37@tds.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Mon, Nov 30, 2009 at 8:26 PM, Wayne Werner <<a href="mailto:waynejwerner@gmail.com">waynejwerner@gmail.com</a>> wrote:<br>
<br>
> A sample of the data is always helpful, but I'll take a shot in the dark.<br>
> If you have data like this:<br>
> 2.31 72<br>
> 98 23<br>
> ... ....<br>
> 34 7.32<br>
> And those are x y pairs you could do something like this:<br>
> f = open('input.txt')<br>
> #List comprehension to read all the lines as [[x1, y1], [x2, y2], ... [xn,<br>
> yn]]<br>
> data = [line.split() for line in f]<br>
<br>
</div>You have to convert the text strings to float somewhere, for example<br>
data = [ map(float, line.split()) for line in f ]<br>
<div class="im"><br>
> # Reorient values as [(x1, x2,... xn), (y1, y2, ... yn)]<br>
> data = zip(*data)<br>
> # plot the xy vals<br>
> pylab.scatter(data[0], data[1])<br>
<br>
</div>Or, IMO a little clearer,<br>
x, y = zip(*data)<br>
pylab.scatter(x, y)<br>
<font color="#888888"><br>
Kent<br>
</font></blockquote></div><br>