massimo sandal wrote:

javi markez bigara ha scritto:

hi everyone,

i would like to know how to plot several linear regresions with the same group of points,

Don't understand exactly what you want to do ...

what do you mean?

however, if you dig the matplotlib and the scipy documentation, you'll find (a)how to plot points (easy) (b)how to calculate linear regressions (this one is less straightforward than it should be, however now I don't remember the details - I can check my code if you have trouble in finding it by yourself).

One easy possibility (using numpy):

In [8]: import numpy as N

# make some sample data with noise

In [9]: x = N.linspace(0,10,100); y = 3*x + 5 + N.random.randn(len(x))*3

In [10]: p = N.polyfit(x, y, 1)

In [11]: p

Out[11]: array([ 3.02862193, 5.14341042])

In [12]: plot(x, y, 'o')

Out[12]: [<matplotlib.lines.Line2D instance at 0xa376aacc>]

In [13]: plot(x, N.polyval(p,x), 'r')

Out[13]: [<matplotlib.lines.Line2D instance at 0xa37734cc>]

Note: matplotlib also has random numbers (e.g. pylab.randn, but I think this is imported from numpy), as well as linspace and also polyfit and polyval, so importing numpy wouldn't even be necessary here. Another lin. reg. function is scipy.stats.linregress .... All roads lead to Rome.

## ···

--

cheers,

steve

Random number generation is the art of producing pure gibberish as quickly as possible.