plotNonconservative.py
1 #!/usr/bin/env python
2 
3 
36 
37 # Authors: Caleb Voss, Wilson Beebe
38 
39 import matplotlib.pyplot as plt
40 from pylab import meshgrid, arange, quiver, quiverkey, sqrt
41 import numpy as np
42 
43 def makeVectorField(f, xmin, xmax, ymin, ymax, step):
44  X, Y = meshgrid(arange(xmin, xmax, step), arange(ymin, ymax, step))
45  U, V = zip(*map(lambda xx: f(*xx), zip(X, Y)))
46  Q = quiver(X, Y, U, V, units='width')
47  quiverkey(Q, 0, 0, 4, '', coordinates='figure', labelpos='W')
48 
49 fig = plt.figure()
50 ax = fig.gca(aspect='equal')
51 x = np.loadtxt("vfrrt-nonconservative.path")
52 makeVectorField(lambda x, y: (y / sqrt(x * x + y * y + 1e-6), -x / sqrt(x * x + y * y + 1e-6)), -6, 6, -6, 6, 0.5)
53 ax.plot(x[:, 0], x[:, 1])
54 plt.show()