Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: how to write a python program tht reads (x,y)

Thread Tools

Re: how to write a python program tht reads (x,y)

John Hunter
Posts: n/a
>>>>> "Selbourne" == Selbourne makhomo <(E-Mail Removed)> writes:

Selbourne> Could you please help me with the following graphs:
Selbourne> 1. python graph that reads in (x,y) data from a file
Selbourne> 2. modify the program to draw a graph of the function
Selbourne> using wxpython 3. python graph that performs a linear
Selbourne> least squares regression, which fits a straight line
Selbourne> through the points 3. plot the straight line in a
Selbourne> different colour to the original graph connecting the
Selbourne> points.

Selbourne> I will appreciate your assistance in this regard.

There are a number of ways to do it, eg, scipy contains everything you
need to do it.

Here is an example script using matplotlib. matplotlib works with wx
(and other GUI toolkits). I'm assuming your data are in two ASCII
columns for x and y.

from matplotlib.matlab import *

data = load('xydata.dat')

x = data[:,0]
y = data[:,1]

#m and b are the best bit slope and intercept
m,b = polyfit(x,y,1) # a line is a 1st order polynomial

# blue dots and red solid line
plot(x, y, 'b.', x, 3*x + b, 'r-')
title('best fit line to noisy data')

You can select wx as your default in the configuration file
..matplotlibrc, or from the command line. Here is a screenshot of the
result in a wx window

The function polyfit is defined in matplotlib.mlab (matplotlib.matlab
imports all these functions too) and does general polygon fitting . A
line is simplest case where the order of the polygon is 1.

If you want to embed matplotlib in a wx application, rather than
simply use it from the shell or in a script, see the
examples/ that comes with the matplotlib src

Good luck!
John Hunter

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How do i write a code that reads a site, then takes the neccisary information Java 5 03-28-2006 06:25 PM
Driver no longer reads burned cd's when they are loaded BUT still reads manufactured cd's no prob JD Computer Support 5 04-14-2005 01:50 AM
Is it possible to write an applet that reads image and data files from web server that is easy for end users? Jean-Paul Lanaux Java 7 05-17-2004 08:23 AM
how to write a python program tht reads (x,y) Selbourne makhomo Python 0 05-16-2004 12:58 PM