Linear regression question

I'm new to matplotlib and am really enjoying using it. I'm confused by something
though:

If I plot the following linear regression it works as expected.

from pylab import *

x = range(10)
y = range(10)

m,b = polyfit(x, y, 1)

plot(x, y, 'yo', x, m*x+b, '--k')
show()

The following code produces an error though (only the length of the vectors have
been changed):

from pylab import *

x = range(11)
y = range(11)

m,b = polyfit(x, y, 1)

plot(x, y, 'yo', x, m*x+b, '--k')
show()

I'm using:
python 2.5
matplotlib 0.98.5.2
numpy 1.3.0

Below is the error message:

Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
  File "/usr/lib/python2.5/site-packages/matplotlib/pyplot.py", line 2096, in plot
    ret = gca().plot(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 3277, in plot
    for line in self._get_lines(*args, **kwargs):
  File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 401, in
_grab_next_args
    for seg in self._plot_3_args(remaining, **kwargs):
  File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 340, in
_plot_3_args
    x, y, multicol = self._xy_from_xy(x, y)
  File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 228, in
_xy_from_xy
    assert nrx == nry, 'Dimensions of x and y are incompatible'
AssertionError: Dimensions of x and y are incompatible
Unbunt Hardy 8.04

Thanks,
Juls

Juls Night wrote:

I'm new to matplotlib and am really enjoying using it. I'm confused by something
though:

[...]

The following code produces an error though (only the length of the vectors have
been changed):

from pylab import *

x = range(11)
y = range(11)

m,b = polyfit(x, y, 1)

plot(x, y, 'yo', x, m*x+b, '--k')

The problem is that x is a list, not an array, and m*x yields an empty array:

In [17]:m*x
Out[17]:

In [18]:m
Out[18]:0.99999999999999978

In [19]:x
Out[19]:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Solution: use
x = arange(11)
y = arange(11)

Eric