Arrows acting funny

I wanted to make a function to take another function that takes a 2d-vector
and returns a 2d-vector, x and y boundaries, and a resolution, and plot the
slope field. However all I get is a blank plot over a small range and some
vertical and horizontal lines. This is my code, if you know differential
equations with the function I'm using you should see a saddle at the origin
and a center at 1,1.

import matplotlib.pyplot as plt

def plot_system(function, xmin, xmax, ymin, ymax, resolution):
xnow = xmin
i = 0
while xnow < xmax:
  ynow = ymin
  while ynow < ymax:
   direction = function([xnow, ynow])
   if direction[0]**2 + direction[1]**2 != 0:
    scale = resolution / (direction[0]**2 + direction[1]**2)**.5
    print repr(direction[0] * scale) + ", " + repr(direction[1] * scale)
    plt.arrow(xnow, ynow, direction[0] * scale, direction[1] * scale)
   ynow = ynow + resolution
  xnow = xnow + resolution
print "plotting"

if __name__ == "__main__":
def function(y):
  return [y[0] - y[0]*y[1], y[0]*y[1] - y[1]]
plot_system(function, -10, 10, -10, 10, 1)


View this message in context:
Sent from the matplotlib - users mailing list archive at